Autor Beitrag
Chemiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 194
Erhaltene Danke: 14

XP, Vista 32 Bit, Vista 64 Bit, Win 7 64 Bit
D7, BDS 2006, RAD Studio 2009+C++, Delphi XE2, XE3, VS 2010 Prof.
BeitragVerfasst: Do 25.02.10 20:31 
Hallo,

hier ein Beispiel:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
unit DEMO_String_umwandeln;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmDemoStringUmwandeln = class(TForm)
    edStringEingabe: TEdit;
    btStringUmwandeln: TButton;
    edStringAusgabe: TEdit;
    procedure btStringUmwandelnClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  frmDemoStringUmwandeln: TfrmDemoStringUmwandeln;

implementation

{$R *.dfm}

procedure TfrmDemoStringUmwandeln.btStringUmwandelnClick(Sender: TObject);
var
  strString: String;
  intZahl: integer;
  dbZahl: double;
  dtDatum: TDateTime;
begin
  strString:= edStringEingabe.Text;
  if TryStrToInt(strString, intZahl) then
  begin
    intZahl:= intZahl+2// Integer-Zahl wird um 2 erhöht
    edStringAusgabe.Text:= inttostr(intZahl);
  end
  else
  begin
    if TryStrToFloat(strString, dbZahl) then
    begin
      dbZahl:= dbZahl+ 44.01// Float-Zahl wird um 44.01 erhöht
      edStringAusgabe.Text:= floattostr(dbZahl);
    end
    else
    begin
      if TryStrToDate(strString, dtDatum) then
    begin
      dtDatum:= dtDatum - 1// Vom Datum wird ein Tag abgezogen
      edStringAusgabe.Text:= Datetostr(dtDatum);
    end
    else
    begin
      edStringAusgabe.Text:= strString; // sonst wird ein Text zurückgeben
    end;
  end;
 end;
end;

end.


Eingabe Ausgabe
10-> 12
12,1-> 56,11
30.12.2009-> 29.12.2009

Bei allen andern Eingaben wird der eingegeben String wieder zurückgegeben.

Bis bald Chemiker