Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling an open form

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
0
0
I have a program where you click on an item in a listview and it dynamically creates a form for the item, with the name of the item. Then it stores the name of that item in a TStringList. (I had a TList, but it wasnt working so I tried a String List, Although I seem to have no luck with either...) Leter I need to access a particular form in the list, so I try to call the form back with this:

(in the OnCreate)
TStringList * MyWindows;
MyWindows = new TStringList;

(when the forms' dynamically created)
MyWindows->Add(NewForm->Name);

(when i need to specifically address the created form)
String to = "myspecialform" /* whatever the form name is */

/* I tried both of these methods without any luck... */
TNewForm* F = (TNewForm*)Form1->MyWindows->[Form1->MyWindows->IndexOf(to)];

TNewForm* F = dynamic_cast<TNewForm*>(Form1->MyWindows->[Form1->MyWindows->IndexOf(to)]);


now all I need to do is access the form that was dynamically created. Maybe I'm going about this all wrong. I have no idea, but It's got me. If anybody can help it would be greatly appreciated Cyprus
 
Greetinx!

In order to acces to dynamically created form you should declare pointer to this form in your main class and/or publish it as property.

Happy programming!))
 
I can't declare a pointer to the form because it's created at runtime. I have to create multiple forms from the same model, but each form has a different name. I need to access one of the forms with a changed name. Am I making sense? Cyprus
 
Hi Cyprus,

You can declare pointers at run-time, or use an array of pointers.
remove the line: Application->CreateForm( __classid(TForm2), &Form2 ); in the projects cpp-file and use the code below in, for instance, a button click event.

best of luck,
Hennie.

TForm2 *FormX[100];
for( int i=0; i<100; i++ ) {
Application->CreateForm( __classid(TForm2), &FormX);
FormX->Left += i;
FormX->Show();
}

 
for some odd reason, characters were removed.
trying again with some additional spaces:

TForm2 *FormX[100];
for( int i=0; i<100; i++ ) {
Application->CreateForm( __classid(TForm2), &FormX [ i ] );
FormX [ i ] ->Left += i;
FormX [ i ] ->Show();
}

 
Greetinx!

You also can create array of pointer to forms and access them with that pointers, like follows:

TForm2 **FormX[100];
for(int j = 0; j < 100; j++)
{
FormX[j] = new TForm2(this);
FormX[j]->Parent - MainForm;
FormX[j]->Left += i;
FormX[j]->Show();
}

Happy programming!))
 
Thank you, very much. but those are both very good ideas, Neither of which I had thought of... I appreciate it more than you know.

btw, hennep: it cut out some of the code because [ i ] represents italics... It screwed me once too ;-) Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top