Referencing a dialog from a different class ?

Referencing a dialog from a different class ?

Postby TimStone » Thu Sep 21, 2017 8:55 pm

I have Dialog A, which calls Dialog B. When B opens, I want to hide A.

In the past, I simply made the object for Dialog A private, and when it called B, I could use a Hide command:
PRIVATE oDlgA
And in the second one:
oDlgA:hide()

Now, however, I am moving everything to classes, and so oDlgA is logged as DATA. When I call Dialog B, oDlgA is not visible. I tried passing it as a parameter, but no success ( it isn't seen )

Is there a function in FW that allows me to see the calling ( Active ) dialog when I open the Method that will use Dialog B ?

Thanks.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Re: Referencing a dialog from a different class ?

Postby TimStone » Fri Sep 22, 2017 4:53 pm

It returns a numeric. So you can't use :hide()

oWdlg:hide()

cannot be replaced with

hDlg := GetActiveWindow( )
hDlg:hide()


However, this does work:

hDlg := GetActiveWindow( )
ShowWindow( hDlg, 0 ) // Hides
then
ShowWindow( hDlg, 1 ) // Shows it again in normal size

Thank you.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Re: Referencing a dialog from a different class ?

Postby TimStone » Fri Sep 22, 2017 5:26 pm

The manual says that does not work from dialogs
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Re: Referencing a dialog from a different class ?

Postby Carlos Mora » Mon Sep 25, 2017 10:37 am

Hi Tim,

TimStone wrote:Now, however, I am moving everything to classes, and so oDlgA is logged as DATA. When I call Dialog B, oDlgA is not visible. I tried passing it as a parameter, but no success ( it isn't seen )

I you don't mind, please post the code where you declare oDlgA, how you call oDlgB and how you pass it as a parameter.

Regards,

Carlos
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: Referencing a dialog from a different class ?

Postby James Bott » Tue Sep 26, 2017 4:35 pm

Tim,

This is how you do it if you are using a codeblock (ON INIT). Remember the issue with self. DlgA will flash (just so you can see it) and then will be hidden by class TTwo's New() method. When DlgB is closed, DlgA will be shown again.

Usually, you only use a dialog's variable in only one method so you could use a Local, but if you needed to reference it in another method of the same class or a different class, you could just pass it as a parameter. If you did it that way, then you wouldn't need to deal with the self issue. But, either way you can make it work.

James

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
    local oTestDlg
    oTestDlg:= TTestDialog():New()
Return nil


Class TTestDialog
   Data oDlgA
   Method New()
endclass

Method New() class TTestDialog
   Local oThis:=self
   define dialog ::oDlgA title "DlgA"
   activate dialog ::oDlgA on init ( TTwo():new( oThis:oDlgA ) )
Return self

class TTwo
   Method new()
endclass

Method New( oDlg ) class TTwo
  Local oDlgB
  oDlg:hide()
  define dialog oDlgB title "oDlgB"
  activate dialog oDlgB center
  oDlg:show()
Return self
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Referencing a dialog from a different class ?

Postby TimStone » Tue Sep 26, 2017 8:20 pm

Here are the two main issues:

1) I have a function which is a pop up dialog. Windows doesn't always handle it well, so I need to use the OF to be sure it stays in focus.
2) I want to inherit the font and other values from the calling dialog, and again this is in a function.

DialogA ( oWdlgA ) is the calling routine in a class.

Dialog B ( oWdlgB ) is the popup dialog called from oWdlgA.

If I used PRIVATE in the calling routine ( PRIVATE oWdlgA ) then I could use OF oWdlgA in the creation of oWdlgB to solve problems 1 and 2,

EXCEPT:

The function may be called from many routines and we don't always know the name of the calling Dialog, and also we don't use PRIVATE in a class.

So that is what I'd like to resolve ....
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Referencing a dialog from a different class ?

Postby James Bott » Tue Sep 26, 2017 8:51 pm

Tim,

First you don't ever HAVE to use Privates. I haven't used them in 15 or 20 years. There is always a another way. Privates are always going to be a source of hard to find and seemly random errors.

So if I understand this correctly, you have a function that you call from several other places, and those places might be another function or a class? It thus seems that what you need is to have the top level dialog visible in either another function or class. So, why can't you just pass the dialog name to these other routines?

someFunction( oDlg )

or,

oSomeObject:someMethod( oDlg )

I'm guessing my assessment isn't right since I am sure you would have already tried the above.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Referencing a dialog from a different class ?

Postby James Bott » Tue Sep 26, 2017 9:32 pm

Tim,

Maybe this is what you are looking for?

James

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
   local oWnd
   define window oWnd
   activate window oWnd on init MyFunction(oWnd)
Return nil

Function MyFunction(oWnd)
   Local oDlg, oBtn
   
   Define dialog oDlg title "DlgA" of oWnd
   @ 3,4 button oBtn of oDlg action TTestDialog():New( oDlg )
   activate dialog oDlg center

Return nil


Class TTestDialog
   Method New()
endclass

Method New( oDlg ) class TTestDialog
   Local oDlgB
   oDlg:hide()
   define dialog oDlgB title "oDlgB" of oDlg
   activate dialog oDlgB center
   oDlg:show()
Return self
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Referencing a dialog from a different class ?

Postby James Bott » Tue Sep 26, 2017 10:44 pm

Tim,

Ok, I think I did it backwards (from what you want) in my last example. You want to call a function from a class. Here it is that way. We are using an ACTION codeblock here.

James

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
   local oWnd
   define window oWnd Title "Dialog Testing"
   activate window oWnd on init TTestDialog():New(oWnd)
Return nil

Function MyFunction(oDlg)
   Local oDlgA
   oDlg:hide()
   Define dialog oDlgA title "DlgA" of WndMain()
   activate dialog oDlgA center
   oDlg:show()
Return nil

Class TTestDialog
   Data oDlgB
   Method New()
endclass

Method New( oDlg ) class TTestDialog
   Local oBtn
   Local oThis:= self
   define dialog ::oDlgB title "oDlgB" of oDlg
   @ 3,4 button oBtn of ::oDlgB action MyFunction( oThis:oDlgB )  
   activate dialog ::oDlgB center
Return self
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests