here with another Trace32 question. A week ago, I wrote a new script that can run any command that my company uses from one central location. It works great when I remember what workspace I am working in (since all file locations are relative to the workspace root) I have the following code implemented today:
PRINT "Workspace is &WORKSPACE"
; Select the action we want to perform.
DIALOG
(
HEADER "Select A Task To Run"
; Large menu below
I have already forgotten to check the debug console more than once and was left scratching my head when I forgot to change workspaces. I want to do something like the following:
; Select the action we want to perform.
DIALOG
(
HEADER &WORKSPACE
But this doesn't compile. Trying HEADER "&WORKSPACE"
doesn't work either as the title just says "&WORKSPACE
" instead of giving me the actual file location (C:\Files\Whatever\
). Is there a way to use a macro or variable to set the window title to a custom string? I can't seem to find a solution. Thanks!
This is a nice one! Good news: There is a solution. (But it is tricky. Easy alternative solution in the end.)
The thing is, that the macro replacement of the PRACTICE scripts work everywhere inside the actual PRACTICE code. However the dialog description is no PRACTICE code: The dialog description is just embedded inside the script. This is like embedding an image (e.g. via a data-URI) in a HTML file. The image is also not HTML.
The command to show a custom dialog is DIALOG.view <dlg-file>
. However the DIALOG.view can also be used with an embedded block (in round braces, which are in separate lines). That is what you do.
And here comes the trick: If you replace the opening brace with (&+
all words starting with &
inside the whole embedded block are replaced with a PRACTICE macro - as long as a macro with that name exist.
So here you go:
PRINT "Workspace is &WORKSPACE"
DIALOG
(&+
HEADER "&WORKSPACE"
; Large menu here...
)
Be aware that the macro replacement appears then really everywhere in the DIALOG block. This can cause unwanted side effects - especially if you have embedded PRACTICE code in your DIALOG. E.g.:
DIALOG
(
BUTTON "Push me"
(
PRIVATE &myfile
DIALOG.File.open *.txt
ENTRY %LINE &myfile
PRINT "You picked file '&myfile'"
)
)
If you enable now macro replacement for the Dialog-block it would also replace the &myfile of the PRIVATE and ENTRY command, which is usually not what you want.
However it should work if you explicitly disable macro replacement down to the PRACTICE script embedded in the DIALOG with "(&-". So you get:
DIALOG
(&+
HEADER "&WORKSPACE"
BUTTON "Push me"
(&-
PRIVATE &myfile
DIALOG.File.open *.txt
ENTRY %LINE &myfile
PRINT "You picked file '&myfile'"
)
)
Other workaround would be to define a macro &myfile which actually contains the text "&myfile":
LOCAL &WORKSPACE &myfile
&WORKSPACE="Select A Task To Run"
&myfile="&"+"myfile" // <- This is the trick!
DIALOG
(&+
HEADER "&WORKSPACE"
BUTTON "Push me"
(
PRIVATE &myfile
DIALOG.File.open *.txt
ENTRY %LINE &myfile
PRINT "You picked file '&myfile'"
)
)
If you've mastered this thing you are close to be a PRACTICE master!
Here is another more easy solution for customizing both the TEXT and HEADER of a custom dialog:
E.g.:
PRIVATE &myheader &mytext
&myheader="Select A Task To Run"
&mytext="zaphod beeblebrox is an awesome frood"
WinPOS ,,,,,,,"&myheader"
DIALOG
(
POS 0 0 30. 1
DlgText1: DYNTEXT ""
)
DIALOG.Set DlgText1 "&mytext"
This 2nd approach simply avoids macro replacement inside the DIALOG description. So it is not an exact answer to the question, but maybe a better solution to the actual problem.