Author Topic: [Solved] - Unable to get text string from TEdit when looping through Components  (Read 467 times)


  • New Member
  • *
  • Posts: 34
I have a series of TabSheets within a group box.  The TabSheets contain 30 TEdit controls.  I want to be able to detect changes in the TEdit text (values).  My plan was to make a call to a single validation procedure from the EdditingDone event of each TEdit where I could loop through all the components, identify the TEdit and then check the value against the original value.

For testing I have the following code in the EdditingDone event of the first of the many TEdit. I am able to identify a TEdit of interest and the following line works but I want to make it general
Code: Pascal  [Select][+][-]
  1. x:=StrToFloat(txtPageLayout1.Text);
I would like to do this but it isn't valid, presumably because some controls don't have text?  So how can I get the text?
Code: Pascal  [Select][+][-]
  1. x:=StrToFloat(Components[I].Text);

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.txtPageLayout1EditingDone(Sender: TObject);
  2. Var
  3.   xOld:    Single; //the existing value set for testing
  4.   i:       Integer;
  5.   x:       Single;
  7. begin
  8. for I:=0 to ComponentCount - 1 do
  9. if Components[i] is TEdit then
  10.    Begin
  11.    xOld:=15;
  12.    If LeftStr(Components[I].Name,14) = 'txtPageLayout1' Then
  13.        Begin
  14.        //The control of interest for checking
  15.        x:=StrToFloat(txtPageLayout1.Text);
  16.        If xOld <> x then ShowMessage('Layout1 was ' + xOld.ToString + '  Changed to ' + x.ToString);
  17.        End
  18.    end;
  19. end;
« Last Edit: April 16, 2021, 10:43:05 pm by Wilko500 »


  • Hero Member
  • *****
  • Posts: 4586
if you assign the same event to all of the edits, then the SENDER of the event will be the EDIT that sent it.

   Name …
The only true wisdom is knowing you know nothing


  • New Member
  • *
  • Posts: 34
Thank you.  Simple, effective.  Just what I needed. 


TinyPortal © 2005-2018