Now we will get a value from APW. To do this, we will create a generic function that takes the name of an APW variable and sets another Delphi variable to the value of the APW variable. Lets call this function GetApwNumber.
Add another unit. Save it as apw.pas. This unit will contain the functions that get and set variables.
Add this code after the interface keyword.
uses WinTypes, WinProcs, sysutils, apwpost; function GetApwNumber( varname : Pchar ; var value : LongInt ; wnd : hWnd ) : Boolean;
Add this code after the implementation keyword.
function GetApwNumber( varname : Pchar ; var value : LongInt ; wnd : hWnd ) : Boolean;
var
varPB : APWC_VARPB;
err: LongInt;
begin
result := false;
varPB.var_Name := varname;
varPB.at_icon_name := nil;
varPB.at_icon_id := 0;
varPB.flags := SV_DONTCREATE;
varPB.eval.ev_type := APW_LONG_TYPE;
err := SendMessage( wnd , APWC_GETVAR , 0 , LongInt( @varpb ) );
if err = EXPR_OK then
begin
value := varPB.eval.long_value;
result := true;
end;
end;
The function takes the name of the variable to get the value of (varname). It also takes a LongInt (value). This will be set to the value of the variable. It also takes the handle of the Authorware window.
The function fills in the required fields in the varPB record, then sends a message which contains the address of the record to APW. The varPB.eval.long_value field is set by APW to the value of the variable. APW then sends a result code back to the UCD. If the result is equal to EXPR_OK then APW was able to complete the request. In this case, out function changes the value parameter and returns true.
On to: Getting a number value from APW
Back to: The apwpost.pas file Start