Sometimes you run a program and you don’t want it to show any dialogs or User Interface at all. For example, if a dialog normally occurs in a program, you would rather not have the application show a MessageBox with the error because that could hang the application.
SYS(2335) - Unattended Server Mode was designed for this. Just turn off UI and instead of displaying a dialog, an error 1031 will be caused, which can be caught with a TRY..CATCH block and logged with no UI shown. The documentation for this function is not quite correct: it states that this function “applies only to .exe automation servers for which the StartMode property equals two.”. Try the code below to see it work when Startmode = 4 (runtime EXE). Comment out the “Exit” line to run the other test cases once you understand how the sample works.
Of course, even with UI disabled, you can call the MessageBox function in the Win32API via DECLARE-DLL For an example of a multithreaded server calling MessageBox, see Webcrawl a blog to retrieve all entries locally: RSS on steroids
SET SAFETY OFF
TEXT TO cstr TEXTMERGE
PROCEDURE Temp(UIMode as string,cTestCase as string) && command line parms are strings
SYS(2335,VAL(UIMode)) && allow or disallow UI
SET SAFETY OFF
_screen.Caption="UIMode = "+UIMode+" "+cTestCase+" Startmode="+TRANSFORM(_vfp.StartMode)
MESSAGEBOX("UI is allowed. UIMode = "+UIMode,0, cTestCase)
*Try this scenario which will bring up a dialog
SELECT * FROM NonExistFile && VFP will bring up dialog to find file
SET SAFETY ON && Cause "Overwrite existing file dialog to appear"
CREATE TABLE temp (name c(10),data m) && Create table with memo file
CREATE TABLE temp (name c(10),data m) && Create table again to cause Overwrite dialog?
MESSAGEBOX("Unknown test case. UIMode = "+UIMode+" "+cTestCase)
CATCH TO oEx
SYS(2335,1) && Allow UI
MESSAGEBOX("Err caught UIMode = "+UIMode+":"+oEx.Message + " " +oEx.details,48,"Exception "+cTestCase)
BUILD PROJECT temp FROM temp
BUILD EXE temp FROM temp
FOR nTestCase=1 TO ALEN(aTestCase)
FOR uiMode=1 TO 0 STEP -1
cCmd="temp "+TRANSFORM(uiMode)+" "+aTestCase[nTestCase]
EXIT && comment this to run the other test cases