📄 halimp.txt
字号:
Automatical Import
------------------
Step by step instructions:
1. Compile and run HALIMP.DPR
2. Import neccesary units with "unit import" dialog.
a) In "Input unit" field select Delphi unit which should be processed
b) In "Output unit" field select output unit name
c) Press button "Import unit"
Program will create output file.
3. Make some changes to output file. (read "Corrections" section below)
4. Add output file to your project. And all imported objects, procedures
and functions will be available for use in scripts.
Manual Import
-------------
Some useful procedures:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) Procedure AddProc(Const Aname: String; ProcAddr: TProcType;
Const Params: Array of byte);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Registers Delphi's procedure or object method in interpreter. After
registration procedure will be accessible in scripts.
AName Procedure name. For registration object method use qualified
name ( 'TOBJECT.FREE')
ProcAddr Import function address. All import functions have this form:
function myinsert(slf:tobject;var s:array of variant):variant;
where
slf - object (for object methods)
s - parameters array.
Params Array of parameters definitions
Params=[2] - no parameters, otherwise type of each parameter
should be specified.
Parameter types:
0 - stack parameter
1 - var parameter
3 - open array parameter
(Open array is passed by interpreter to import function in
variant with array type. Format of this array: V[0] - array
size. V[1]..V[V[0]] - array items.)
Example:
// import function
function myTSTRINGSAPPEND(slf:tobject;var s:array of variant):variant;
begin
TSTRINGS(slf).APPEND(S[0]);
End;
// registration call. This line should present in initialization section
AddProc('TSTRINGS.APPEND',myTSTRINGSAPPEND,[0]);
Other examples can be found in \HALDPK subdirectory.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2)Procedure AddFun(Const Aname: String; ProcAddr: TProcType;
Const Params: Array of byte);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Registers Delphi's functions or object method in interpreter. After
registration function will be accessible in scripts. parameters are the
same as in AddProc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3)Procedure AddProp(Const Aname: String; ProcAddr, SetProcAddr: TProcType);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Registers non-array object properties in interpreter.
AName - Object property name. For example 'TOBJECT.CLASSNAME'
ProcAddr - Address of interface function for reading property
SetProcAddr - Address of interface function for writing property.
Nil if property is readonly.
Example:
// import function for getting property
Function TSTRINGSget_TEXT(slf:tobject;var s:array of variant):variant;
Begin
Result := TSTRINGS(slf).TEXT;
End;
// import function for setting property
Function TSTRINGSset_TEXT(slf:tobject;var s:array of variant):variant;
Begin
TSTRINGS(slf).TEXT:=S[0];
End;
// registration call. this line should present in initialization section
AddProp('TSTRINGS.TEXT',TSTRINGSget_TEXT,TSTRINGSset_TEXT);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
4)Procedure AddArrayProp(Const Aname: String; ADim: Integer;
ProcAddr, SetProcAddr: TProcType);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Registers array properties in interpreter
AName - Object property name. For example 'TOBJECT.CLASSNAME'
ADim - array property dimension. For example if property is declared
as 'property A[Index1,Index2:Integer]:String' then its
dimension is 2.
ProcAddr - Address of interface function for reading property
SetProcAddr - Address of interface function for writing property.
Nil if property is readonly.
Example:
// import function for getting array property
Function TStringsget_Strings(slf:tobject;var s:array of variant):variant;
Begin
Result := TSTRINGS(slf).Strings[S[0]];
End;
// import function for setting array property
Function TStringsset_Strings(slf:tobject;var s:array of variant):variant;
Begin
TStrings(slf).Strings[S[0]]:=S[1];
End;
// registration call. Should present in initialization section
AddArrayProp('TSTRINGS.STRINGS',1,TSTRINGSget_Strings,TSTRINGSset_Strings);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5) Procedure VarToConsts(Var V: Variant; Var P: Array of tvarrec;
Var MaxP: Integer);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Converts variant to array of constants. Returns Maxp - high bound of array.
Use only in interface functions.
Example:
function myTDATASETINSERTRECORD(slf:tobject;var s:array of variant):variant;
var R:Array[0..100] of tvarrec;
maxr:integer;
begin
VarToConsts(S[0],R,maxR);
TDATASET(slf).INSERTRECORD(slice(r,maxr));
disposeconsts(R,maxr);
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6)Procedure disposeconsts(Var c: Array of tvarrec; size: integer);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Releases memory occupied by array of constants, converted using
function VARTOCONSTS. Example see above.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7) Function ObjToVar(S: TObject): Variant;
Function OV(S: TObject): Variant;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Converts object to variant. Used when writing interface functions.
Example:
Function TDATABASEget_PARAMS(slf:tobject;var s:array of variant):variant;
Begin
Result := ObjToVar(TDATABASE(slf).PARAMS);
End;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8)Function VarToObj(S: Variant): TObject;
Function VO(S: Variant): TObject;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Converts variant to object. Used when writing interface functions.
Example:
Function TDATABASEset_PARAMS(slf:tobject;var s:array of variant):variant;
Begin
TDATABASE(slf).PARAMS:=TStrings(VarToObj(S[0]));
End;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9) Procedure AddConst(Const AName: String; V: Variant);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Registers constant with name ANAME and with value V. After registration
constant will be accessible in scripts.
Example:
// this line should present in initialization section
AddConst('Pi',pi);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10) Procedure VarToStringS(Var V: Variant; Var P: Array of String;
Var MaxP: Integer);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Converts variant to array of string. Returns Maxp - high bound of array.
Used only in interface functions.
Corrections
------------
Automatical import procedures are not perfect. Here is some solutions
for problems you may encounter:
1. Error:
Incompatible types 'Variant' and 'Pointer'
Incompatible types 'TListSortCompare' and 'Variant'
Solution:
Use ObjToVar and VarToObj functions
2. Error:
Cannot assign to readonly property
Solution:
Remove interface function for setting property
3. Error:
Types of actual and formal var parameters must be identical
Solution on example:
Before modification:
function myTSTRINGLISTFIND(slf:tobject;var s:array of variant):variant;
begin
Result := TSTRINGLIST(slf).FIND(S[0],S[1]);
End;
After modification:
function myTSTRINGLISTFIND(slf:tobject;var s:array of variant):variant;
Var
Index:integer;
begin
Index:=S[1];
Result := TSTRINGLIST(slf).FIND(S[0],Index);
S[1]:=Index;
End;
4. Array properties import functions and registration call should be corrected
5. Constructor import functions and registration call should be corrected
6. If imported function contain open array as parameter then registration call
should be corrected. (type of parameter should be changed)
7. Set and enumeration types wasn't implemented in interpreter, so it won't
understand functions and procedures with parameter of 'set' type.
However enumeration types can be emulated with AddConst registration
procedure
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -