Link to home
Start Free TrialLog in
Avatar of SemperFudge
SemperFudge

asked on

Accessing dynamically created frames stored in page control

hi,
this may be an easy question, but i can't figure it out.
i'm creating pages(frames) dynamically and storing them in a PageControl.
I need to be able to search the pagecontrol for the individual frame that i want
(searching by the caption) and then run a procedure on that frame that dynamically
creates a text box.
I am able to search and find the correct page, but i can't seem to access it to
run the procedure, any ideas?
Here is the code:
begin
 i := 0;
 cfound := false;
 repeat
   if (PageControl1.Pages[i].Caption = Category) then       
   begin
     cfound := true;
   end
   else
   begin
     i := i + 1;
   end;
 until ((cfound = true)OR(i = PageControl1.PageCount-1));
 if (cfound = true) then
 begin   //found the category, place the new field in it      
     //PROBLEM HERE
     //PageControl1.Pages[i].
    
 end//if
the code needs to go into the spot indicated.
I know i need to use PageControl.Pages[i] to indicate the page...but
PageControl.Pages[i].Procedure(v); will not work.
any help is appreciated.
Avatar of DiegoC
DiegoC

This is what you need?:

var
   ed: TEdit;
/////
The code to found the page
/////

//YOUR PROBLEM
if (cfound = true) then
begin   //found the category, place the new field in      
     ed:=TEdit.Create(Application);
     ed.parent:=PageControl1.Pages[i];
     ed.Left :=200;
     ed.Top:=40;
     //And you can set all the properties of ed Tedit  

end//if

Explanation: Set the parent is the key

Let me know if you need something else.
Regards

Diego


Avatar of SemperFudge

ASKER

That's not excatly what i want to do.

I already have the code to add the control, it's a function in a frame...i want to call that function.

Here is the function i use to add a new Tab to my PageControl:

----------------------------------------------
procedure TBlockFrame.NewTab(Sender: TObject;
    var Name: string; var Value: string; var DataBlock: string;
    var Category: string);

var
NewTabSheet: TTabSheet;
FFrame:TCIFFrame;
begin
  NewTabSheet:= TTabSheet.Create(PageControl1);
  //CREATE NEW CATEGORY TAB
  with NewTabSheet do
  begin
    PageControl := PageControl1;
    Visible := true;
    Caption := Category;
    PageControl1.ActivePage := NewTabSheet;
  end;

  FFrame := TCIFFrame.Create(NewTabSheet);
  FFrame.Visible := false;
  FFrame.Parent := NewTabSheet;

  FFrame.NewField(Sender,Name,Value,DataBlock);

  FFrame.Align := alClient;
  FFrame.Visible := true;
  FFrame.BringToFront;

end;
----------------------------------------------

That above function is called when i want to add a new tab and a new field in the new tab.


The function i included in my first post is one where i already have created the proper tab in the past, and i want to just call the function on the frame to add a new field to it.


in the above function, i call
FFrame.NewField(Sender,Name,Value,DataBlock);
which calls the function in the frame to create the new field.


I want to be able to call this function from my original function (the one in my first post), but i can't figure out how to specify the frame asscociated with the tab.





ASKER CERTIFIED SOLUTION
Avatar of j42
j42

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that's exactly what i wanted, thanks!
Hi SemperFudge,

thanks for the flowers. Just some additional comments: Sometimes you want to avoid to maintain two seperate lists (MyList.Items[i] and PageControl1.Pages[i]) since it can cause alot of debugging. I am not sure but I guess there is a Tag property you can use:

FFrame := TCIFFrame.Create(NewTabSheet);
PageControl1.Pages[i].Tag := FFrame; // Typcast neccessary?

and

//PROBLEM HERE
//PageControl1.Pages[i]
TCIFFrame(PageControl1.Pages[i].Tag).Procedure(v);

Best of luck
J