Procedure Data Type

A Procedure data type is a reference to a procedure.  

The default is NoProcedure. For example, in the ATEasy Internal library, we have a String procedure called "Right(sStr, lChars)", which returns the lChars leftmost characters of the string sStr. And we have another procedure named "Left(sStr, lChars)" which returns the lChars rightmost characters of the string sStr. Now you create a variable "proc" with data type of Procedure. Then you could assign "proc" to have different values in your code:

proc = Internal.Right ! Without the parentheses after the procedure name

Print proc("ATEasy is Easy", 4) ! Result is "Easy"

proc = Internal.Left

Print proc("ATEasy is Easy", 6) ! Result is "ATEasy"

Note: Any form procedure or event must be called from that form or a form of the same type. If your program calls a procedure by using a variable (of type Procedure, for example, the above "proc"), and the procedure it references is a form procedure (either a procedure of the form or one of its events, or subcomponent procedures or events), then that call must be from within the same form. ATEasy does not check the arguments of the Procedure variable (for example, "proc") at design time. When you try to execute it at run time, ATEasy will check the arguments by looking for the referenced form procedure within the scope of that form.

Assigning Procedure to String and vice versa

You can assign a string to Procedure or set proc variable to a string containing a proc name. This makes convenient to set a user defined procedure name at the run time.  In the following example, GetOption() returns a string, proc name.

! retrieve detect procedure

procDetectUUT=GetOption(enOptionsDetectUUTProcedure)

if procDetectUUT=NoProcedure

return

endif

! the following sets other module's public proc:

proc="FaultAnalysis.ShowAnalyzeForm"

if proc

proc(aobProgram, GetCurrentForm().hWnd, IsModal())

endif

More examples that set string to a procedure and vice versa:

proc="DMM.SetFunction"
proc="SetFunction"
proc="RELAY.gxsw32.Gx6616Close"
proc=sModule+"."+"SetFunction"

sProc=Internal.Left     
sProc=TestExec.cmdProgramExit

Checking Procedure Variable

Check if procedure variable is empty by comparing with NoProcedure or check the variable itself:

If proc=NoProcedure then return

If proc then proc()
 

Callback

A procedure variable or a procedure can be passed to DLL that later can call the ATEasy procedure from within the DLL:

 

User32.EnumWindows ( EnumWindowsCallbackFunction, 0x090A0B0C )

where EnumWindowsCallbackFunction is an ATEasy procedure.  For further info, see DLL Example: Passing Callback Procedure parameters by Value.
 

Storage

A Procedure data type variable is stored in a size of 4 bytes' memory.

See Also

Basic Data Types, Data Conversion, Numeric, Strings, User Defined Date Types, AddHandler, RemoveHandler, NoProcedure