FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Referencing a dialog from a different class ?
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Referencing a dialog from a different class ?
Posted: Thu Sep 21, 2017 08: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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Referencing a dialog from a different class ?
Posted: Fri Sep 22, 2017 07:19 AM
Tim,

Try

Code (fw): Select all Collapse
GETACTIVEWINDOW()


EMG
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Referencing a dialog from a different class ?
Posted: Fri Sep 22, 2017 04: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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Referencing a dialog from a different class ?
Posted: Fri Sep 22, 2017 05:20 PM
Or you can use

Code (fw): Select all Collapse
OWNDFROMHWND()


EMG
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Referencing a dialog from a different class ?
Posted: Fri Sep 22, 2017 05: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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Referencing a dialog from a different class ?
Posted: Fri Sep 22, 2017 08:44 PM

Right. Sorry.

EMG

Posts: 989
Joined: Thu Nov 24, 2005 03:01 PM
Re: Referencing a dialog from a different class ?
Posted: 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"
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Referencing a dialog from a different class ?
Posted: Tue Sep 26, 2017 04: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 (fw): Select all Collapse
#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
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Referencing a dialog from a different class ?
Posted: Tue Sep 26, 2017 08: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Referencing a dialog from a different class ?
Posted: Tue Sep 26, 2017 08: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Referencing a dialog from a different class ?
Posted: Tue Sep 26, 2017 09:32 PM
Tim,

Maybe this is what you are looking for?

James

Code (fw): Select all Collapse
#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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Referencing a dialog from a different class ?
Posted: 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 (fw): Select all Collapse
#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

Continue the discussion