![]() |
check TEdit field
Hi,
I have a Form which contains six TEdit component, i would like to check whether the TEdit field is empty or not, i can do it with the following code
Code:
is it possible to do it in another way, for example
procedure TForm1.Button1Click(Sender: TObject);
begin if (Edit1.Text<>'')and (Edit2.Text<>'') and (Edit3.text<>'') and (Edit4.Text<>'')and (Edit5.Text<>'') and (Edit6.text<>'')then ShowMessage('Edit field not empty ') else ShowMessage('Edit fieldempty ') end;
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin If (TEdit(Sender).Text <>'') then ShowMessage('Edit field not empty ') else ShowMessage('Edit fieldempty ') end; |
AW: check TEdit field
Delphi-Quellcode:
Here is a little helper function:
procedure TForm1.Button1Click(Sender: TObject);
begin // Sender contains a reference to "Button1" so the following code // is not correct and will fail If (TEdit(Sender).Text <>'') then ShowMessage('Edit field not empty ') else ShowMessage('Edit fieldempty ') end;
Delphi-Quellcode:
Using the helper function you can write:
function EditHasData(edit:TEdit):Boolean;
begin // TrimRight removes blanks result := TrimRight(edit.Text) <> ''; end;
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin if EditHasData(Edit1)and EditHasData(Edit2) and EditHasData(Edit3) and EditHasData(Edit4)and EditHasData(Edit5) and EditHasData(Edit6) then ShowMessage('all Edits are filled with data') else ShowMessage('there is at least one empty Edit'); end; |
AW: check TEdit field
Another suggestion:
Delphi-Quellcode:
function DataComplete(const EditArray: array of TEdit): Boolean;
var i: integer; begin Result := true; for i := Low(EditArray) to High(EditArray) do begin Result := trim(EditArray[i].Text) <> ''; if not Result then break; end; end; procedure TForm1.Button1Click(Sender: TObject); begin if DataComplete([Edit1, Edit2, Edit3, Edit4, Edit5, Edit6]) then ShowMessage('All Edits are filled') else ShowMessage('At least one Edit is empty'); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:16 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz