Recent

Author Topic: (Solved)How To?  (Read 973 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
(Solved)How To?
« on: October 09, 2020, 04:39:12 am »
   So the following code throws an error if i turn on the second line. 
Is there a way to make this work? I want to set the Text in TEdit.Text to TEdit1.Text := '';
I know that Tedit.Text will work but I have 50 TEdits on a form. Thus the loop to enable them and I need to clear the text property.

 
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3.      for i:= 0 to ComponentCount-1 do
  4.         if Components[i] is TControl then begin
  5.             TControl(Components[i]).Enabled:=True;
  6.            TControl(Components[i]).text := '';                     { <===Error}
  7.         end;
  8.      end;                  
  9.  
  10.  

Thanks
« Last Edit: October 09, 2020, 05:53:46 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

bytebites

  • Hero Member
  • *****
  • Posts: 640
Re: How To?
« Reply #1 on: October 09, 2020, 05:08:07 am »
Code: Pascal  [Select][+][-]
  1.      for i:= 0 to ComponentCount-1 do
  2.         if Components[i] is TEdit then begin
  3.             TControl(Components[i]).Enabled:=True;
  4.             TEdit(Components[i]).text := '';                    
  5.         end;
  6.      end;  

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How To?
« Reply #2 on: October 09, 2020, 06:25:12 am »
It didn't work as expected.

Attached the program. It's  a very small demo.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

nummer8

  • Full Member
  • ***
  • Posts: 111
Re: How To?
« Reply #3 on: October 09, 2020, 11:34:12 am »
Form in demo project was not visible for me. My screen was to small.
Changed the Form Left and Form Top to 0 in lfm file. After that the form was visible.

I changed the procedure below in your project. That worked without errors or problems.

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.ControlClearCB;
  3.  var i : Integer;
  4.   begin
  5.        for i:= 0 to ComponentCount-1 do
  6.         if Components[i] is TEdit then begin
  7.           TEdit(Components[i]).text := '';
  8.         end;
  9. end;  
  10.  

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: How To?
« Reply #4 on: October 09, 2020, 05:52:46 pm »
Yes, Works great. Just what I was looking for,

Thank You.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018