Specific Aspects of Delphi Type Mapping |
Top Previous Next |
Delphi – OleVariant mapping
As described above, because Delphi and COM have different type systems, we need to convert Delphi types to/from OleVariant. Here resulting variant type-codes, which correspond to specific Delphi type conversion, will be specified:
Additional mapping utilities
There some utilities hard-coded in System.pas wrapper unit to support Delphi to OleVariant mapping in scrip code.
Script utilities for working with Delphi sets
Following utilities are used for working with Delphi 'set' types:
S = SetEmpty Include S, fsBold Exclude S, fsBold S = SetMake(fsBold, fsItalic) If SetIn(fsBold, s) then...
SetEmpty function returns empty set that is a set without any element included. Include and Exclude functions works like corresponding Delphi functions. Note that first argument – is ByRef argument. SetMake works like Delphi set contructor [fsBold, fsItalic]. The function takes variable numbers of parameters. SetIn function works like Delphi 'in' operator. The returned value type is Boolean.
Though set are represented as integers (varInteger variant type code), it is not convenient to use integer operations, like +, - with sets.
Note: our PasScript language supports working with sets natively. It uses the Delphi syntax, like:
S := []; Include(S, fsBold); Exclude(S, fsBold); S := [fsBold, fsItalic]; if fsBold in s then...
Script utilities for working with Delphi records
Following utilities are used for working with Delphi records:
Set R = TPoint.Create R.X = 7 R.Y = 9 Set R2 = R.Copy If RecIs(R, TPoint) Then...
Because records are represented as IDispatch objects, they actually have reference type semantic in script code. So, you have to use Create pseudo-constructor to create new record instance before you can use it. Also, simply assigning R to R2 you will just copy a reference to record; this will not create two different records; so, you have to use Copy pseudo-function to make real record copy. RecIs function just helps you to test record type. Function return value type is Boolean.
Note: our NativeVb language supports working with records naturally with its New and TypeOf/Is syntax:
Set R = New TPoint If TypeOf R Is TPoint Then...
PasScript language also supports testing of record type using its is operator:
R := TPoint.Create; if R is TPoint then...
Script utilities for working with event handlers
Another one function available in System.pas wrapper unit for creating script event handlers – is EventMake:
Sub Button1Click(Sender) MsgBox “Hellow World!” End Sub
Button1.OnClick = EventMake(“Button1Click”)
Use EventMake function to create a reference to script event handler inside script code. Note, that from Delphi code you can use EventToVariantS global function, providing a reference to script control as a context (AContext parameter).
Note: out native languages supports event handler syntax naturally:
|