Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index of DBEdit controls.

Status
Not open for further replies.

Guthro

Technical User
Sep 9, 2006
107
0
0
GB
Dimbo question and I apologise if this is the 100th time its been asked.

Assuming this help example.
~~~~~~~~~~
procedure TForm1.Table1BeforePost(DataSet: TDataSet);

begin
if DBEdit1.Text = '' then
Abort;

end;
~~~~~~~~~~

If I have 10 such DBEdits on a form, how can I test for all without 10 lines of ifs ?
I know you need to create a loop but what do you index with a loop counter ?
I've tried with DBEdit[loopcount] but I can never get it to work.
I'm still stuck with a "Basic" mindset with some commands and need a few slaps across the face to get this to sink in !



My Feeblegirl.com Forum boards for mmorpgs, sport, fun, politics...
 
if you set your fields Required property to true then delphi handles all of that for you.

Aaron
 
Aaron has given you the best answer, but to answer your original question:
Guthro said:
I know you need to create a loop but what do you index with a loop counter ?
Code:
[navy][i]// for automatic syntax highlighting see faq102-6487 
[/i][/navy][b]procedure[/b] TForm1.Button1Click(Sender: TObject);
[b]var[/b]
  c : Integer;
[b]begin[/b]
  [b]for[/b] c := [purple]0[/purple] [b]to[/b] ComponentCount - [purple]1[/purple] [b]do[/b]
    [b]if[/b] (Components[c] [b]is[/b] TDBEdit) [b]and[/b] (TDBEdit(Components[c]).Text = [teal]''[/teal]) [b]then[/b]
      Abort;
[b]end[/b];

This code will cycle through all components on your form and check only the TDBEdit controls to see if their Text property is an empty string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top