Finding dynamically created controls on dynamically created TTabSheets

Finding dynamically created controls on dynamically created TTabSheets

Post by Uwe » Thu, 04 Sep 2003 08:39:17


Hi

I'm creating the TabSheets of a TPageControl at runtime. On each TabSheet
there is a dynamically created TMemo, which is filled with text from a file
the user has selected. The file path is temporarely stored in the Hint
property of the corresponding TabSheet. What I would like to do is to
implement a "Save All" function. So, how can I iterate over the TabSheets
and save the content of each TMemo back to its original file?

TIA
Uwe
 
 
 

Finding dynamically created controls on dynamically created TTabSheets

Post by Ignacio Va » Thu, 04 Sep 2003 08:50:22


3f552a1c$ XXXX@XXXXX.COM ...

TPageControl.Pages

Cheers,
Ignacio

 
 
 

Finding dynamically created controls on dynamically created TTabSheets

Post by Uwe » Thu, 04 Sep 2003 09:06:13

Hi Ignacio

Using pagecontrol.pages is obvious. Below is the code I came up with so far.
It doesn't work, of course, but am I at least on the right track?


procedure TForm1.Action3Execute(Sender: TObject);
var
I, K: Integer;
TheFileName: String;
begin
for K := 0 to PageControl1.PageCount -1 do
for I := 0 to PageControl1.ControlCount - 1 do
if PageControl1.Controls[I] is TMemo then
with TMemo(PageControl1.controls[I]) do
begin
TheFileName := PageControl1.Pages[K].Hint;
TMemo(PageControl1.controls[I]).Lines.SaveToFile(TheFileName);
end;
end;


Thanks for your help
Uwe
 
 
 

Finding dynamically created controls on dynamically created TTabSheets

Post by Rube » Thu, 04 Sep 2003 09:07:51

hi,

procedure TForm1.SaveAll;
var
i, j : integer;
begin
with PageControl1 do
for j := 0 to (PageCount - 1) do
with Pages[j] do
begin
for i := 0 to (ControlCount -1 ) do
begin
if Controls[i] is TMemo then
(Controls[i] as TMemo).Lines.SaveToFile(Controls[i].Parent.Hint);
end;
end;
end;


g,
Ruben




file
 
 
 

Finding dynamically created controls on dynamically created TTabSheets

Post by Ignacio Va » Thu, 04 Sep 2003 09:21:29


3f55306c$ XXXX@XXXXX.COM ...

Almost. Changed lines are marked with a vbar:

| for I := 0 to PageControl1.Pages[K].ControlCount - 1 do
| if PageControl1.Pages[K].Controls[I] is TMemo then
| with TMemo(PageControl1.Pages[K].controls[I]) do
| TheFileName:=Hint;
| Lines.SaveToFile(TheFileName);

Cheers,
Ignacio
 
 
 

Finding dynamically created controls on dynamically created TTabSheets

Post by Uwe » Thu, 04 Sep 2003 09:36:16

Hi Ignacio

That was it, thanks a lot!

Cheers
Uwe