UI_DLG_OPTIONAL_EVENT Function
Syntax
Arguments
- title
The name of the dialog.
- event
The name of the event to pass.
- immediate
Optional. Default = .F. Whether to wait until the event is processed. .T. = Wait until event is processed. .F. = Do not wait.
Description
Invoke an action event in the named dialog, but only if named dialog exists.
Discussion
The UI_DLG_OPTIONAL_EVENT() function invokes an action event in the specified dialog, but only if the specified dialog exists. This allows you to leave out code in your script that tests to see if the dialog actually exists (using the ui_modeless_dlg_exist() function).
Example
This example receives and displays status from multiple user defined functions.
function status_list as v ()
dim completed as C
dim message2 as C
completed = ""
ui_modeless_dlg_box("StatusList",<<%dlg%
Completed:;
[.100,5^#completed];
Current task:;
[.100message2?.t.];
;
%dlg%,<<%code%
if (a_dlg_button = "close") then
ui_modeless_dlg_close("statuslist")
end if
if (atc("Completed:",a_dlg_button) = 1) then
completed_i = substr(a_dlg_button,11)
completed = completed + crlf()+ completed_i
completed = remove_blank_lines(completed)
ui_modeless_dlg_refresh("statuslist")
end if
if (atc("Working:",a_dlg_button) = 1) then
message2 = substr(a_dlg_button,9)
ui_modeless_dlg_refresh("statuslist")
end if
%code%)
end functionThe calling user defined function calls the StatusList dialog with variations of the following syntax:
ui_dlg_optional_event("StatusList", "working:Listing files in " + directory, .t.)
ui_dlg_optional_event("StatusList", "completed:Adding " + directory + " files to database", .t.)The following example sends an event from the parent modeless dialog to the embedded child modeless dialog.
ui_modeless_dlg_box("ParentDialog",<<%dlg%
{startup=init}
{frame=1,1}
{embedded=40,20:ChildDialog};
{lf};
{sp};
%dlg%,<<%code%
if a_dlg_button = "Hello" then
ui_dlg_optional_event("ChildDialog","Hello",.t.)
ui_msg_box("","Another message from the parent dialog")
end if
if a_dlg_button = "init" then
a_dlg_button = ""
show_embedded(local_variables())
end if
if a_dlg_button = "close" then
ui_modeless_dlg_close("ParentDialog")
end if
%code%)
function show_embedded as v (vars as P)
with vars
ui_modeless_dlg_box("ChildDialog",<<%dlg%
{wrap=40}
This is an embedded dialog box that responds to the Hello event sent to it from its parent.;
{lf};
Name: [.20name];
{lf};
Enter a name into the Name field and click this button. After 2 seconds, the "Hello" dialog box will appear.;
{lf};
;
%dlg%,<<%code%
if a_dlg_button = "Hello" then
sleep(2)
ui_msg_box("","Hello: " + name)
end if
%code%)
end with
end functionLimitations
Desktop applications only.
See Also