Program execution [examples]

Terminate session
QUIT
// Quit if [ABANDON] was pressed
if lastkey()=ctrl('g')
    quit
endif

https://www.lianja.com/doc/index.php/QUIT


Terminate the session and return a message or status code
EXIT
exit("User "+user()+ " exited at "+time())

https://www.lianja.com/doc/index.php/EXIT()


Terminate session returning a message or status code

DIE
die("User "+user()+ " exited at "+time())

https://www.lianja.com/doc/index.php/DIE()


Compile one or more program files
COMPILE
compile *.prg

https://www.lianja.com/doc/index.php/COMPILE


Pause program execution for a specified number of seconds
SLEEP
private lRunning = .T.
do while lRunning
  if not file("C:\temp\message.txt")
    ? time()
    sleep 5
    loop
  endif
 
  fd = fopen("C:\temp\message.txt")
  cMessage = fgets(fd)
  ? cMessage
  if cMessage = "STOP"
    lRunning = .F.
  endif
  fclose(fd)
  erase C:\temp\message.txt
enddo

https://www.lianja.com/doc/index.php/SLEEP


Execute a list of commands
EXEC
? exec("open database southwind","use example","browse")

https://www.lianja.com/doc/index.php/EXEC()


Run multiple lines of code
EXECSCRIPT
// Character field
create table scripts (script char(200))
use scripts
append blank
replace script with "for i=1 to 10" + CHR(13) + "?i" + CHR(13) + "endfor" + CHR(13)
execscript(script)
 
// Text constant
execscript("for i=1 to 10" + CHR(13) + "?i" + CHR(13) + "endfor" + CHR(13))
 
// Memory variable
m_script = "for i=1 to 10" + CHR(13) + "?i" + CHR(13) + "endfor" + CHR(13) 
execscript(m_script)
 
// Including parameters
execscript("parameters p1,p2"+chr(13)+"messagebox(p1+etos(p2))"+chr(13),"Hello ",2013)

https://www.lianja.com/doc/index.php/EXECSCRIPT()


Enable or disable automatic recompiling of modified source programs
SET_COMPILE
set compile on
do myprog

https://www.lianja.com/doc/index.php/SET_COMPILE


Determine which files need to be compiled
SET_DEVELOPMNET
set compile on
set development on
do prototype

https://www.lianja.com/doc/index.php/SET_DEVELOPMENT


Stops event processing started with READ EVENTS
CLEAR_EVENTS
clear events

https://www.lianja.com/doc/index.php/CLEAR_EVENTS


Execute a Visual FoxPro style form
DO_FORM
do form recipes

https://www.lianja.com/doc/index.php/DO_FORM


Execute all pending Windows events
DOEVENTS
doevents

https://www.lianja.com/doc/index.php/DOEVENTS


Process identity
GETPID
? getpid()
     14586
pid = getpid()
? type("pid")
N

https://www.lianja.com/doc/index.php/GETPID()


Execute an operating system command or external program
RUN
run "C:\Program Files (x86)\Lianja\bin\lianjaruntime.exe"

https://www.lianja.com/doc/index.php/RUN


Execute an external program and optionally wait for its completion
SPAWN
spawn db printrep
pid = spawnpid()
on escape killed = cancelpid(pid)
if not activepid(pid)
    ? "Printing completed."
endif

https://www.lianja.com/doc/index.php/SPAWN


Activity of identified process
ACTIVEPID
spawn db program
? activepid(spawnpid())
.T.

https://www.lianja.com/doc/index.php/ACTIVEPID()


Cancel a sub-process
CANCELPID
spawn db program
m_activepid = spawnpid()
if activepid(m->m_activepid)
    if cancelpid(m->m_activepid)
        dialog box "Process Canceled."
    else
        dialog box "Process couldn't be Canceled."
    endif
else
    dialog box "There is no Process Active."
endif

https://www.lianja.com/doc/index.php/CANCELPID()


Spawned process identity
SPAWNPID
spawn db program
m_activepid = spawnpid()
if activepid(m->m_activepid)
    if cancelpid(m->m_activepid)
        dialog box "Process Canceled "
    else
        dialog box "Unable to Cancel Process."
    endif
else
    dialog box "There is no Process Active".
endif

https://www.lianja.com/doc/index.php/SPAWNPID()


Reinitialize the Lianja environment
CLEAR_ALL
clear all

https://www.lianja.com/doc/index.php/CLEAR_ALL


Include another source file in the current program
INCLUDE
//Check user details before proceeding
public validuser
#include "checklogin.ch"
if not validuser
    return
endif
...

https://www.lianja.com/doc/index.php/INCLUDE


Determine how an application is being run
ISSERVER
if isserver()
   // running via server
endif

https://www.lianja.com/doc/index.php/ISSERVER()


Return the ‘do’ level of the currently executing program or procedure
DOLEVEL
> ? dolevel()
         0
//master.prg
procedure subproc1
? dolevel()
?
return
 
? dolevel()
subproc1()
//end of master.prg
> do master
         1
         2

https://www.lianja.com/doc/index.php/DOLEVEL()


Return the ‘do’ level of the currently executing program or procedure
LEVEL
> ? level()
         0
//master.prg
procedure subproc1
? level()
?
return
 
? level()
subproc1()
//end of master.prg
> do master
         1
         2

https://www.lianja.com/doc/index.php/LEVEL()


Evaluate a character expression and return the result
EVALUATE

 

use demo
? evaluate("customer.last_name")
Siegel
? evaluate("1+1")
2
m_var = "DATE() > {01/01/2001}"
? evaluate(m_var)
.T.

https://www.lianja.com/doc/index.php/EVALUATE()


When creating a desktop shortcut for running the Lianja App Builder or for runtime Lianja Apps there are several command line options that can be specified.

The following table provides details of the currently available command line options. These can be combined to customize the running of an App e.g.

lianja --app orderprocessing --maximized
lianja myprogram.dbo
lianjaruntime --kiosk --fullscreen --runtimecaption "Our company Apps"
lianjarun --kiosk --fullscreen --runtimecaption "Our company Apps"

The full Target is:

C:\lianja\bin\lianjaruntime.exe 
C:\lianja\cloudserver\tenants\public\apps\myapp\start
--nosplashscreen

Note: If you are running some custom program code that is going to take a long time to complete e.g. consolidating inventory, then you can provide feedback to the user via a system tray icon on the desktop e.g.

tray = createObject("SystemTrayIcon")
tray.icon = "app:/myapp.png"
tray.showMessage("Message", "Consolidating inventory...")
// perform some long running operation to consolidate inventory
tray.showMessage("Message", "Consolidation completed...")

Advertisements