Page 1 of 1
DcBrowseCol TIPBLOCK <-> GetTooltip
Posted: Sat Sep 15, 2012 2:13 am
by skiman
Hi Roger,
With TIPBLOCK the tooltip is in the same thread, this way the open aliases can be used. It seems as GETTOOLTIP is in another thread, so the open aliases can't be used.
In my application I have a GET for a customer name. I wanted to use the GETTOOLTIP to show the customer address and phone number in a tooltip. This isn't working, unless I call a function which opens the customer.dbf again, and search the customer to get the desired result.
Is this for a special reason?
Re: DcBrowseCol TIPBLOCK <-> GetTooltip
Posted: Sun Sep 16, 2012 8:22 am
by rdonnay
I wrote this for Michael Rudrich:
Code: Select all
/*
This sample shows how to use data-driven techniques
to display SAY prompts and BUTTON captions via Sub-Classing.
Tooltips are displayed in another thread.
This solution works even though it accesses a database.
*/
#INCLUDE "dcdialog.CH"
FUNCTION Main()
LOCAL GetList[0], bToolTip := {|o|o:toolTipText}
DC_LoadRdds()
@ 0,0 DCSAY {|o|GetText(1,o)} TOOLTIP bToolTip SAYSIZE 20 SUBCLASS 'SayText()'
@ 1,0 DCSAY {|o|GetText(2,o)} TOOLTIP bToolTip SAYSIZE 20 SUBCLASS 'SayText()'
@ 2,0 DCSAY {|o|GetText(3,o)} TOOLTIP bToolTip SAYSIZE 20 SUBCLASS 'SayText()'
@ 3,0 DCSAY {|o|GetText(4,o)} TOOLTIP bToolTip SAYSIZE 20 SUBCLASS 'SayText()'
@ 4,0 DCSAY {|o|GetText(5,o)} TOOLTIP bToolTip SAYSIZE 20 SUBCLASS 'SayText()'
@ 6,0 DCPUSHBUTTONXP CAPTION {|o|GetText(5,o)} TOOLTIP bToolTip SIZE 20,2 FONT '10.Arial Bold' ;
SUBCLASS 'ButtonText()'
DCREAD GUI FIT SETAPPWINDOW
RETURN nil
* ----------
PROC appsys ; RETURN
* ----------
FUNCTION GetText( nWhich, oXbp )
LOCAL nFound, cText := '?????', aText, nSaveArea := Select()
DEFAULT nWhich := 0
IF Select('TEXT') == 0
USE text NEW INDEX text VIA 'FOXCDX'
ENDIF
TEXT->(OrdSetFocus('NUMBER'))
IF TEXT->(dbSeek(nWhich))
cText := Trim(TEXT->text)
oXbp:toolTipText := Trim(TEXT->tooltip)
ELSE
oXbp:toolTipText := '?????'
ENDIF
SELECT (nSaveArea)
RETURN cText
* ------------
CLASS SayText FROM DC_XbpStatic
EXPORTED:
VAR toolTipText
ENDCLASS
* ------------
CLASS ButtonText FROM DC_XbpPushButtonXP
EXPORTED:
VAR toolTipText
ENDCLASS
Re: DcBrowseCol TIPBLOCK <-> GetTooltip
Posted: Sun Sep 16, 2012 11:34 pm
by skiman
Hi Roger,
I'm confused about your solution.
Why should you use subclassing in this case?
Code: Select all
FUNCTION GetTooltip( nWhich)
LOCAL cTooltip :=""
DEFAULT nWhich := 0
USE text NEW INDEX text VIA 'FOXCDX'
TEXT->(OrdSetFocus('NUMBER'))
IF TEXT->(dbSeek(nWhich))
cTooltip := Trim(TEXT->tooltip)
ENDIF
close TEXT
RETURN cTooltip
If you use gettooltip {|| gettooltip(x) } the tooltip will be shown.
In my application we have codeblocks where we can define the tooltip text. This can be a lot of information, and I don't know which aliases will be used. I will open all the possible DBF files in my tooltip function. Probably I can check for the existing of the aliasname in the string of the codeblock. If "CUSTOMER" $ upper(cCodeblock) and so on.
Re: DcBrowseCol TIPBLOCK <-> GetTooltip
Posted: Mon Sep 17, 2012 6:57 am
by rdonnay
I used a subclass because I needed a variable to hold the tooltip.
This worked very well for Michael because he needed it to work only with one database. His application converts text to different languages.
I will try to find a better solution for you.
Re: DcBrowseCol TIPBLOCK <-> GetTooltip
Posted: Mon Sep 17, 2012 8:22 am
by rdonnay
Here is a solution that you may find to be satisfactory.
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "appevent.CH"
#DEFINE SEND_TOOLTIP xbeP_User+1
FUNCTION Main()
LOCAL GetList[0], GetOptions, oBrowse, oDlg, cToolTip := ''
USE \exp19\data\xtest
DCUSEREVENT SEND_TOOLTIP ACTION {|c|cToolTip := &c}
@ 0,0 DCBROWSE oBrowse ALIAS 'XTEST' SIZE 50,10 FIT
DCBROWSECOL FIELD XTEST->city HEADER 'City' PARENT oBrowse WIDTH 20
DCBROWSECOL FIELD XTEST->state HEADER 'State' PARENT oBrowse WIDTH 10
DCBROWSECOL FIELD XTEST->areacode HEADER 'Area' PARENT oBrowse WIDTH 3
DCBROWSECOL FIELD XTEST->exchange HEADER 'Exch' PARENT oBrowse WIDTH 3
DCBROWSECOL FIELD XTEST->number HEADER 'Number' PARENT oBrowse WIDTH 3
@ 12,0 DCSAY 'Place your mouse here to see tooltip 1' FONT '12.Arial Bold' SAYSIZE 0 ;
TOOLTIP {||SendToolTip('XTEST->city + XTEST->state',oDlg),cToolTip}
@ 14,0 DCSAY 'Place your mouse here to see tooltip 2' FONT '12.Arial Bold' SAYSIZE 0 ;
TOOLTIP {||SendToolTip('XTEST->areacode + XTEST->exchange + XTEST->number',oDlg),cToolTip}
DCGETOPTIONS TOOLTIPFONT '12.Lucida Console Bold' TOOLTIPCOLOR GRA_CLR_BLACK,GRA_CLR_YELLOW
DCREAD GUI FIT TITLE 'Tooltip Test' EVAL {|o|oDlg := o} SETAPPWINDOW OPTIONS GetOptions
RETURN nil
* ----------
PROC appsys ; return
* ----------
STATIC FUNCTION SendToolTip( cToolTip, oDlg )
DEFAULT oDlg := SetAppWindow()
PostAppEvent( SEND_TOOLTIP,cToolTip,,oDlg )
DC_CompleteEvents()
RETURN nil
Re: DcBrowseCol TIPBLOCK <-> GetTooltip
Posted: Mon Sep 17, 2012 11:48 pm
by skiman
Hi Roger,
Thanks for this interesting sample. I never use the DCUSEREVENT. I have to look closer to this.
Re: DcBrowseCol TIPBLOCK <-> GetTooltip
Posted: Mon Sep 17, 2012 11:59 pm
by skiman
Hi Roger,
rdonnay wrote:I used a subclass because I needed a variable to hold the tooltip.
Since you can use @ x,y dcsay "Caption" tooltip 'This is my tooltip' ... There is already a variabele that holds the tooltip?
I'm using the following for my translations. Belgium is a little country, but we have 3 official languages: Dutch, French and German.
Code: Select all
@ x,y dcsay fMessage(nText) tooltip fMessage(nText,.T.) ....
Function fMessage(nText,lTooltip)
Local cResult
Static nPrevText := 0
Default lTooltip := .F.
if nPrevText # nText
DbfText->(dbseek(nText)
nPrevText := nText
endif
if lTooltip
cResult := alltrim(dbfText->(fieldget(fieldpos("tooltip"+cLanguage))))
else
cResult := alltrim(dbftext->(fieldget(fieldpos("text"+cLanguage))))
endif
return cResult