Xdialogs Are Built from Strings

Many developers do not necessarily realize, or at least appreciate the significance of the fact, that the arguments to UI_DLG_BOX() and UI_MODELESS_DLG_BOX() are just strings that can be manipulated in Xbasic. The ramifications of this are really profound. This fact gives the developer the ability to dynamically construct dialogs on the fly.

In other words, instead of defining an xdialog like this (which is how most of the examples are written):

ui_dlg_box("Test",<<%dlg%
Name: [.20name];
<OK>;
%dlg%,<<%code%
if a_dlg_button = "OK" then
'do something
end if
%code%)

You could set up your Xdialog like this:

dim dlg_body as C
dim dlg_event as C

 

dlg_body = <<%dlg%
Name: [.20name];
<OK>;
%dlg%

dlg_event = <<%code%
if a_dlg_button = "OK" then
'do something
end if
%code%

ui_dlg_box("Test",dlg_body,dlg_event)

While the second example iis more verbose that the example in red, it does bring home the point that dlg_body, and dlg_event are just strings that you can easily manipulate, or dynamically construct, using Xbasic code before calling the ui_dlg_box()command.

Example

The following, somewhat trivial, example demonstrates how the dlg_body string is constructed dynamically using Xbasic before the dialog is shown.

Note that this example is different than a dynamic Xdialog where controls are hidden or shown in real time
 as the state of variables change. You can create dynamic Xdialog using the {condition} statement in the
Xdialog body.

dim fn as C
dim ln as C
dim married as L
dim sp_fn as C
dim sp_ln as C

fn = "Jim"
ln = "Jones"
married = .t.
sp_fn = "Sheila"
sp_ln = "Wood"

dim dlg_body as C
dim dlg_married as C
dim dlg_single as C

 

dlg_married = <<%dlg%
First name: |[.20fn];
Last name: |[.20ln];

{lf};
Spouce's Name:;
First name: | [.20sp_fn];
Last name: | [.20sp_ln];
%dlg%

dlg_single = <<%dlg%
First name: |[.20fn];
Last name: |[.20ln];
%dlg%

if married then
dlg_body = dlg_married
else
dlg_body = dlg_single
end if

ui_dlg_box("Name",dlg_body)

Supported By

Alpha Five Version 5 and Above