Forum > LCL

TStringGrid vs. With

(1/2) > >>

Procedure TForm1.LightGrid;
  i:= Form1.ControlCount;
  for ii := 0 to i - 1 do
  if Form1.Controls[ii] is TStringGrid then
  showmessage(Form1.Controls[ii].Name); This line worked well.
    with Form1.Controls[ii] do  What should I do with this line?
    Flat:= true;   Error message - Identifier 'Flat' not found.
    borderstyle:= bsnone;
    Options:= Options - [goVertLine];   Error message - Identifier 'Options' not found.
    end; //with
    end; //if
end;     //procedure       


--- Code: ---if Form1.Controls[ii] is TStringGrid then
  with TStringGrid(Form1.Controls[ii]) do

--- End code ---


This worked with only TStringGrids exactly on Form1.
But in Form1, there are lots of TPageControl.
And each TpageControl, there are lots of  TTabSheets.

"LightGrid;" didn't work with TStringGrids on every TTabSheet.

I would like "LightGrid;" to work with all TStringGrids in everywhere they are in.
What code should be written more?


--- Code: ---Procedure TForm1.LightGrid;
  for ii := 0 to Form1.ControlCount - 1 do  //  no need for a variable - limit isn't recalculated
  if Form1.Controls[ii] is TStringGrid then begin            // <<< begin here
  showmessage(Form1.Controls[ii].Name); [b][color=red]This line worked well.[/color][/b]
  // that's  because any control has a name. cast Controls[ii] to stringgrid to access the rest
    with Form1.Controls[ii] as TStringGrid do begin
      Flat:= true;   
      BorderStyle:= bsnone;
      Options:= Options - [goVertLine];   
    end; //with
  end; //if
end;     //procedure       

--- End code ---

It still worked with only TStringGrid exactly on TForm.
But it did not touch any TStringGrid in TPageControl or TTabSheet.

.ControlCount didn't count TStringGrid in TPageControl or TTabSheet.

I saw an idea; "visible".

How can I apply this property to such procedure?


[0] Message Index

[#] Next page

Go to full version