AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

check TEdit field

Ein Thema von question · begonnen am 10. Okt 2013 · letzter Beitrag vom 11. Okt 2013
Antwort Antwort
question

Registriert seit: 17. Apr 2013
97 Beiträge
 
#1

check TEdit field

  Alt 10. Okt 2013, 22:38
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:
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;
is it possible to do it in another way, for example
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin

If (TEdit(Sender).Text <>'') then
     ShowMessage('Edit field not empty ')
  else
    ShowMessage('Edit fieldempty ')

end;
  Mit Zitat antworten Zitat
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
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: check TEdit field

  Alt 11. Okt 2013, 07:25
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;
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:01 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz