Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Accessing dynamically created frames stored in page control

Posted on 2003-03-12
5
Medium Priority
?
282 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:SemperFudge
  • 2
  • 2
5 Comments
 

Expert Comment

by:DiegoC
ID: 8124394
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


0
 

Author Comment

by:SemperFudge
ID: 8124634
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.





0
 
LVL 2

Accepted Solution

by:
j42 earned 280 total points
ID: 8126509
Hi SemperFudge,

You can use a TList to store a reference of the frame. Once you got the index of the PageControl.Page you can get the frame.

----------------------------------------------
procedure TBlockFrame.NewTab(Sender: TObject;
   var Name: string; var Value: string; var DataBlock: string;
   var Category: string);
...
FFrame := TCIFFrame.Create(NewTabSheet);
MyList.Add(FFrame);   // ************** NEW CODE ***********

----------------------------------------------
if (cfound = true) then
begin   //found the category, place the new field in it      
    //PROBLEM HERE
    //PageControl1.Pages[i]
  TCIFFrame(MyList.Items(i)).Procedure(v);  // ******** NEW CODE ****



Regards
J
0
 

Author Comment

by:SemperFudge
ID: 8132766
that's exactly what i wanted, thanks!
0
 
LVL 2

Expert Comment

by:j42
ID: 8134776
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question