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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple files

Status
Not open for further replies.

sputnic

Programmer
Dec 24, 2000
6
0
0
US
Hi, this is probably basic, but it is driving me nuts. I built two programs totaly seperate from each other with Builder5. I am trying to use a button on one form to open the other program/form modaly and do stuff with that one, then exit and go back to the first one. It seems that with some tinkering I can get them to work, but I hate doing it that way, I try it the same way with another program that has a lot of variables and then I get multiple declarations, it never seems to be the same. When I cleared those out of the way, I get a duplicate declaration error on this statment "TDisplayMessage *DisplayMessage;" I put a #ifndef statement in there and then the next line won't work...right on down the line. Basicaly, how do you get two forms to work together without conflicting???
thnx for the patience.
Sputnik
 
Hi,

It's hard to catch what may be wrong for sure. Your problem may be due that file 1 includes file 2 and file 2 includes file 1. Kind of round trip. It is most of the time possible to get out of this kind of problem by a careful organisation of declarations and definitions.

I don't know if this is relevant to your problem, but why not creating a third object, (an "association class") whose role would be to hold a pointer to an instance of each form, and to manage the communication between each form.

In this case, the forms don't have to know each other; instead, they need to know their father. You avoid the "round trip" include loop.

Then Form1 accesses Form2's methods by something like this:

TForm1::CallerMethod()
{
...
father->CallForm2sMethod();
...
}

where CallForm2sMethod implements the call you need to Form2.


Hope that helps

Woliwol
 
Visit Borland (Inprise): C++ Builder. They can get you big help with C++ Builder. Here is the older versions of Borland C++.
 
so you want to open another program in your first one? if thats what you want, do this:

char *WinIP="C:\\WINDOWS\\WINIPCFG";

//selects the program and how to use it
SHELLEXECUTEINFO exeinfo;
memset(&exeinfo, 0, sizeof(exeinfo));
exeinfo.cbSize=sizeof(exeinfo);
exeinfo.lpVerb="Open";
exeinfo.lpFile=WinIP;
exeinfo.fMask=SEE_MASK_NOCLOSEPROCESS;
exeinfo.nShow=SW_SHOWDEFAULT;

if (!ShellExecuteEx(&exeinfo))
{
MessageDlg(&quot;Your IP config. file is missing.&quot;, mtError, TMsgDlgButtons() << mbOK,0);
return;
}

This will open WinIPCfg, the program to find your local IP address. you can modify it to open any other program just like that. Cyprus
 
Technicaly, I don't want to open a seperate file, I want to compile it into one larger file, makes it simpler for persons using it when I e-mail it to them. I guess want to make it modal, they have to finish it to get back to the original window. I want to compile the first program, get it working then make a second that will do something else. Then put a button on the first the will run the second in a modal window then when that one is done close it and return to the first window. I have gotten this to work, but it seems to be guess work, I thought just including the second file and then using SecondWindow->ShowModal() would work, but I can't just incluse the *.cpp file because some of the initializing...I assume... is being done behind the scenes in other files that Borland creates, when I try to include those files, I get errors. I hope I didn't just confuse the issue, but it is the best I can do. Thanx, and I will have to make a note of how to make files run seperately, it is a good idea.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top