merging a DCSAY from a codeblock in a gui-Window

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
obelix
Posts: 48
Joined: Tue Dec 03, 2013 7:44 am
Location: Villingen-Schwenningen, Black Forest, Germany

merging a DCSAY from a codeblock in a gui-Window

#1 Post by obelix »

Hi everybody,
maybe my question will cause a LoL, but i'll try it nevertheless:

#include "dcdialog.ch"

proc main()
local cvar1,cvar2
cvar1="text function"
cvar2="text udf"
@ 1,1 DCSAY "text 1" get cvar1
x={||test2()}
DCREAD GUI
return

function test2
@ 2,1 DCSAY cvar2
return .t.
Is there any way to show these two textes in the same window?
quiet old but still young and unskilled in express++

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: merging a DCSAY from a codeblock in a gui-Window

#2 Post by rdonnay »

The answer is YES, but I don't understand what you are trying to do.
The eXpress train is coming - and it has more cars.

User avatar
obelix
Posts: 48
Joined: Tue Dec 03, 2013 7:44 am
Location: Villingen-Schwenningen, Black Forest, Germany

Re: merging a DCSAY from a codeblock in a gui-Window

#3 Post by obelix »

hi Roger,
I want to use the same headline in different windows. For being able to change the look or the behavior of the dcsay-Statements easily it would be helpful to
put it into a function, but when I display the window, the elements of the function are not shown.


//insted of:
@ 0,0 DCSTATIC TYPE XBPSTATIC_TYPE_TEXT SIZE wcol,wrow OBJECT oStatic1
* used in many windows
@ 2,5 dcsay w_rahmtext1 SAYFONT textfont1
@ 3,5 dcsay w_rahmtext2 SAYFONT textfont1
@ frow,fcol dcsay wnr SAYFONT textfont1
@ 4,2 DCSAY repl("_",wcol-2) SAYCOLOR color1,color2 SAYFONT textfont1
* end
@ 6.2 DCSAY ....

//I would prefer:
@ 0,0 DCSTATIC TYPE XBPSTATIC_TYPE_TEXT SIZE wcol,wrow OBJECT oStatic1
headlines(w_rahmtext1,w_rahmtext2,wnr)
@ 6.2 DCSAY ....

function headlines
parameters w_rahmtext1,w_rahmtext2,wnr
* used in many windows
@ 2,5 dcsay w_rahmtext1 SAYFONT textfont1
@ 3,5 dcsay w_rahmtext2 SAYFONT textfont1
@ frow,fcol dcsay wnr SAYFONT textfont1
@ 4,2 DCSAY repl("_",wcol-2) SAYCOLOR color1,color2 SAYFONT textfont1
* end
quiet old but still young and unskilled in express++

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: merging a DCSAY from a codeblock in a gui-Window

#4 Post by rdonnay »

Put your SAY text into a Code block.

Code: Select all

@ 2,2 DCSAY {||HeadLine()} SAYSIZE 20

DCREAD GUI


FUNCTION HeadLine()

RETURN 'This is my head line'
The eXpress train is coming - and it has more cars.

User avatar
Tom
Posts: 1179
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: merging a DCSAY from a codeblock in a gui-Window

#5 Post by Tom »

Put your SAY text into a Code block.
This will not return what Obelix wants.

The best way to do this would be to use the preprocessor:

Code: Select all

#include 'dcdialog.ch'
#command HEADLINES <nStartLine>,<cHeadLine1>,<cHeadLine2>,<cFont> ;
        => @ <nStartLine>,5 DCSAY <cHeadLine1> SAYFONT <cFont> ;;
           @ <nStartLine>+1,5 DCSAY <cHeadLine2> SAYFONT <cFont>
#pragma library("dclipx.lib")

FUNCTION Main()

HEADLINES 2.5,'Hallo','Welt','12.Tahoma'

@ 6,1 DCPUSHBUTTON CAPTION 'Test' SIZE 10,1 ACTION {||MsgBox('Test')}

DCREAD GUI FIT ADDBUTTONS

RETURN nil
The "HEADLINES"-statement can be used everywhere. The PP-directive creates the correct code at the line where the "HEADLINES"-statement resides.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
obelix
Posts: 48
Joined: Tue Dec 03, 2013 7:44 am
Location: Villingen-Schwenningen, Black Forest, Germany

Re: merging a DCSAY from a codeblock in a gui-Window

#6 Post by obelix »

Thank you Tom, that's what I looked for, a little bit compicated but really helpful.
Rogers suggestion (codeblock) didn't work.
quiet old but still young and unskilled in express++

User avatar
Tom
Posts: 1179
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: merging a DCSAY from a codeblock in a gui-Window

#7 Post by Tom »

Great! :)

It's not very complicated. The #command-directive forces the preprocessor to replace the command ("HEADLINES") with the code behind the "=>", using the parameters declared. This is no magic. The PP looks for matching code and replaces it with what you tell to replace. A #define-directive does nothing else then to replace every matching text inside the code with the value declared:

Code: Select all

#define MASTERPASSWORD "MyMasterPassword"
...

IF cPassWord == MASTERPASSWORD 
...
This translates the code into 'IF cPassWord == "MyMasterPassword"' before it's going to be compiled. It's like you're running a "Search&Replace" in your source code editor. Same with #command.

If you use the code I posted, remember that you now are able to change your "HEADLINES" code only once to create an effect for your whole app, but it does not force PBUILD to recompile every PRG effected. You may use PBUILD /all if you change it. Place the code in a .CH-file included in all PRGs which use it.

The preprocessor is a very powerful instrument. At least, eXpress++ is a proof for this, since the usage of PP-functionalities are the core of it.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
obelix
Posts: 48
Joined: Tue Dec 03, 2013 7:44 am
Location: Villingen-Schwenningen, Black Forest, Germany

Re: merging a DCSAY from a codeblock in a gui-Window

#8 Post by obelix »

Thank you, Tom for the explanation. It really works good (after having found out
that the #pp-commands are case sensitive !)
quiet old but still young and unskilled in express++

User avatar
jdsoft
Posts: 113
Joined: Thu Jan 28, 2010 1:13 pm
Location: Overberg
Contact:

Re: merging a DCSAY from a codeblock in a gui-Window

#9 Post by jdsoft »

Ok, try this:

Code: Select all

Procedure Main()
LOCAL cVar1,cVar2, x
LOCAL GetList := {}
cVar1 := "text function"
cVar2 := "text udf"
@ 1,1 DCSAY "text 1" get cVar1
If .T. // Same result
   x={||Test2(GetList,cVar2)}
   Eval(x)
Else
   Test2(GetList,cVar2)
Endif
DCREAD GUI
return

Function test2(GetList,cVar2)
@ 2,1 DCSAY {||cVar2} 
return .t.
Not sure what you want, but you can refresh cVar2, and call Dc_Getrefresh(Getlist,.....)

Jack Duijf
Regards,
Jack Duijf

Post Reply