Lazarus

Programming => General => Topic started by: Wilko500 on April 16, 2021, 01:21:12 am

Title: [Solved] - Unable to get text string from TEdit when looping through Components
Post by: Wilko500 on April 16, 2021, 01:21:12 am
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;
  6.  
  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;
Title: Re: Unable to get text string from TEdit when looping through Components on form
Post by: Wilko500 on April 16, 2021, 10:41:56 pm
Thank you.  Simple, effective.  Just what I needed. 
TinyPortal © 2005-2018