Autor Beitrag
Kralle
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65

Windows XP,Win7
Delphi 6, Turbo Delphi Pro, Delphi 7 Enterprise, Delphi XE2 Lazarus
BeitragVerfasst: So 16.09.12 18:24 
Hallo,

ich möchte sicherstellen, dass ein TEdit.Text nicht leer sein darf.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm2.E_WertKeyPress(Sender: TObject; var Key: Char);
    // Nur Zahlen erlauben
    begin
        if NOT (Key in [#08,'-''0'..'9']) then
                Key := #0;
   if E_Wert.GetTextLen = 0 then
      Bt_Start.Enabled:=true
   else
         Bt_Start.Enabled:=false;
end;


Aber, egal wie versuche auf Leer abzufragen, es klappt nicht.

a) siehe oben
b) Length => 0
c) Text <>''

Immer das Gleiche. Nach dem ersten Zeichen wird "Bt_Start.Enabled:=true" und wenn man dann mittels der "Backspace"-Taste die eingegebenen Zahlen löscht, dann
ich auch nach der letzen Zahl immer noch "Bt_Start.Enabled:=true"

Teilweise gibt es ein False, wenn man nach der letzten Zahl nochmal BS drückt.

Wie stelle ich sicher fest, ob Text eine Zahl (+/-) enthält?

MfG
Heiko

Moderiert von user profile iconMartok: Delphi-Tags hinzugefügt
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 16.09.12 18:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm2.E_WertChange(Sender: TObject);
var
 d:Double;
begin
      Bt_Start.Enabled:=Length(E_Wert.Text)>0;
      if TryStrToFloat(E_Wert.Text,d) then
        begin
            if d>=0 then Caption := 'positv'
            else Caption := 'negativ';
        end else Caption :='';

end;

procedure TForm2.E_WertKeyPress(Sender: TObject; var Key: Char);
begin
        if NOT (Key in [#08,'-''0'..'9']) then
                Key := #0;

end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS

Für diesen Beitrag haben gedankt: Kralle
Kralle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 65

Windows XP,Win7
Delphi 6, Turbo Delphi Pro, Delphi 7 Enterprise, Delphi XE2 Lazarus
BeitragVerfasst: So 16.09.12 19:51 
Moin,

user profile iconbummi hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
      if TryStrToFloat(E_Wert.Text,d) then					


Den Befehl kannte ich überhaupt noch nicht.

Jetzt läuft es - Danke.

MfG
Heiko