Recent

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

Wilko500

  • Jr. Member
  • **
  • Posts: 64
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;
« Last Edit: April 16, 2021, 10:43:05 pm by Wilko500 »
MacBook Pro mid 2015 with OS Monterey 12.7.2
FPC 3.3.1 Lazarus _3_0

Wilko500

  • Jr. Member
  • **
  • Posts: 64
Thank you.  Simple, effective.  Just what I needed. 
MacBook Pro mid 2015 with OS Monterey 12.7.2
FPC 3.3.1 Lazarus _3_0

 

TinyPortal © 2005-2018