May 18, 2024, 11:09:25 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Dialog Question

Started by Bruce Peaslee, December 31, 2005, 03:29:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

More OOP confusion ;)

My program has a bunch of child windows. When the mouse hovers over one, another window opens and shows some data. I am now trying to get where if I click on the window, it opens a dialog. The example colorcontrols.src has the dialog defined in main(), but if I do that, how do I then call DoModal from a class method?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Bruce Peaslee

OK, I stuck the DoModal call into a subroutine called from the method. At least it appears. Now I will see if I can access the data properly.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

As long as the variable hasn't fallen out of scope yet, you can access it, although you'll need a pointer to it first. The 'this' pointer does that for you, so any data and functions can be accessed even if you're not calling it from main(). But once main() returns, you can't access it anymore. Of course, that's not a problem since the program ends when main() returns.

Bruce Peaslee

January 01, 2006, 09:34:09 AM #3 Last Edit: February 25, 2006, 11:23:45 AM by peaslee
I'm still not getting it.

The program looks something like this:

class mapwindow:cwindow
...
mapwindow::OnLButtonDown
{
// here is where I want to DoModal
}
...
global sub main()
{
// here is where the dialog is defined
def d1 as dlg;
d1.create(...);
...
}
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

January 01, 2006, 10:17:21 AM #4 Last Edit: January 01, 2006, 10:26:36 AM by Ionic Wizard
There are dozens of ways to do this. Use a variable in your MapWindow class.

dialog *mydialog.

When you create the MapWindow set the variable to the address of the dialog you created.

pMap->myDialog = &d1;

Then you can execute DoModal from that method

myDialog->DoModal();

Another way would be to create the dialog in the MapWindow class..again using the variable in the MapWindow class....using NEW of course

It all depends on what the dialog is used for.  If it is only used by the MapWindow class then let that class manage it, putting it in your  'main' sub is just making you do extra work.  If I were to have a dialog that was only used in a single class then it would be dynamically allocated.

class SomeClass
{
declare OnCreate();
declare SomeClass();
declare _SomeClass();
declare InitStuffDialog();
dialog *ShowStuff;
}

SomeClass::SomeClass()
{
ShowStuff = NULL;
return;
}

SomeClass::_SomeClass()
{
if(ShowStuff)
   Delete ShowStuff;
return;
}

SomeClass::InitStuffDialog()
{
ShowStuff = new(dialog,1);
ShowStuff->Create(...);
ShowStuff->AddControl(...);
...
return;
}

SomeClass::OnCreate(),int;
{
InitStuffDialog();
return;
}


Paul.
Ionic Wind Support Team

Bruce Peaslee

Thanks. I will work on this tomorrow.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Bruce Peaslee

January 02, 2006, 12:11:17 PM #6 Last Edit: January 02, 2006, 12:27:35 PM by peaslee
Quote from: Ionic Wizard on January 01, 2006, 10:17:21 AM
There are dozens of ways to do this...
There are even more ways not to do it!ÂÃ,  ÂÃ, :D

I used the last example and it works perfectly. Thanks for your patience as well as your help.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

Your welcome ;)

Dialogs will be easier to use as we progress.
Ionic Wind Support Team