Recent

Author Topic: To filter controls in a form  (Read 5146 times)

asdf

  • Sr. Member
  • ****
  • Posts: 310
To filter controls in a form
« on: March 16, 2011, 05:57:30 am »
if Form1.Tpagecontrol number(1-6, except 7-12) > 0 then begin
for n:= 0 to Form1.Tpagecontrol number(1-6, except 7-12)-1 do begin
if Form1.Controls[n] is TPageControl then begin
StringGrid1.Cells[0,n+1]:=MainScreenForm.Controls[n].Name;
end;
end;
end;   

How can I replace blue-colored words ?               
« Last Edit: March 16, 2011, 06:01:06 am by asdf »
Lazarus 1.2.4 / Win 32 / THAILAND

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: To filter controls in a form
« Reply #1 on: March 16, 2011, 10:12:15 am »
Got it

Code: Pascal  [Select][+][-]
  1. if Form1.ControlsCount > 0 then begin
  2.   for n:= 0 to Form1.ControlsCount -1 do begin
  3.     if Form1.Controls[n] is TPageControl then begin
  4.       StringGrid1.Cells[0,n+1]:=MainScreenForm.Controls[n].Name;
  5.  
  6.       if Form1.Controls[n] {?????} > 0 then begin  // How can I count tabsheet quantity ?]
  7.         for q:= 0 to Form1.Controls[n] {?????} -1 do begin
  8.         end;
  9.       end;
  10.  
  11.     end;
  12.   end;
  13. end;    
  14.  
« Last Edit: March 16, 2011, 12:38:36 pm by Marc »
Lazarus 1.2.4 / Win 32 / THAILAND

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: To filter controls in a form
« Reply #2 on: March 16, 2011, 12:39:45 pm »
added code formatting tags
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: To filter controls in a form
« Reply #3 on: March 16, 2011, 12:45:33 pm »
something like:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.xyz;
  2. var
  3.   pc: TPageControl;
  4.   n: Integer;
  5. begin
  6. .
  7. .
  8.   // better don't access the global Form1 variable directly
  9.   // if this is a method of Form1, you can access ControlsCount directly
  10.   //if Form1.ControlsCount > 0
  11. //  if ControlsCount > 0
  12. //  then begin  
  13. // no need to if, the forloop already dot this for you
  14.  
  15.     for n:= 0 to ControlsCount -1 do
  16.     begin  
  17.       if not (Controls[n] is TPageControl) then Continue;
  18.  
  19.       pc := TPageControl(Controls[n]);
  20.       // From1 ??? MainScreenForm ??? this looks messy
  21.       // StringGrid1.Cells[0,n+1] := MainScreenForm.Controls[n].Name;  
  22.       StringGrid1.Cells[0,n+1] := pc.Name;  
  23.    
  24.       //  if Form1.Controls[n] {?????} > 0 then begin  // How can I count tabsheet quantity ?
  25.       // access pc.tabs here
  26. .
  27. .
  28. .
  29.   end;      
  30. //end;
  31.  
« Last Edit: March 16, 2011, 12:47:55 pm by Marc »
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: To filter controls in a form
« Reply #4 on: March 17, 2011, 05:21:31 am »
Thank you so much  :) .
Lazarus 1.2.4 / Win 32 / THAILAND

 

TinyPortal © 2005-2018