Einzelnen Beitrag anzeigen

Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#2

AW: check TEdit field

  Alt 10. Okt 2013, 23:57
Delphi-Quellcode:
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;
Here is a little helper function:
Delphi-Quellcode:
function EditHasData(edit:TEdit):Boolean;
begin
  // TrimRight removes blanks
  result := TrimRight(edit.Text) <> '';
end;
Using the helper function you can write:
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;
fork me on Github
  Mit Zitat antworten Zitat