Request
The following script represents my problem.program test; uses Forms, StdCtrls; var fr : TForm; me: TMemo; begin fr := TForm.create(nil); try me := TMemo.create(fr); me.parent := fr; me.lines.clear; fr.showmodal; finally fr.free; end; end.
If I execute the script above I get error:
Object Project1.exe raised exception class Exception with message 'Class "TMemoStrings" is not registered.'.
It is produced, when I call »memo1.lines.clear«. I looked into StdCtrls.pas, and found TMemoStrings class declared under implementation section. It's not possible to register it outside unit. I'll be greatfull if you could find solution. I'm using Delphi 2007.
You have to use fake methods to register virtual abstract methods. For example:
procedure TStrings_Clear(Self: TStrings); begin self.Clear; end; .................................... G := RegisterClassType (0, TStrings); RegisterHeader (G, 'procedure Clear; ', @TStrings_Clear);
Request
How I could register an overloadesd procedure/function for scripting engine?Solution
You need to find out address of the procedure (function). It is more easy to explain it on an example. Let's suppose we have 2 overloaded procedures:You can use the following code to obtain the addresses:procedure MyProc(const S: String); overload; begin writeln(1); end; procedure MyProc(I : Integer); overload; begin writeln(2); end;Now you can register the overloaded procedures for paxCompiler engine:function Address1: Pointer; type TMyProc = procedure (const S: String); var P: TMyProc; begin P := MyProc; Move(P, result, 4); end; function Address2: Pointer; type TMyProc = procedure (I: Integer); var P: TMyProc; begin P := MyProc; Move(P, result, 4); end;RegisterHeader(0, 'procedure MyProc(const S: String); overload;', Address1); RegisterHeader(0, 'procedure MyProc(I : Integer); overload;', Address2);
Request
How I could register an overloadesd method for scripting engine? In particular, how I could register an overloaded virtual method?Solution
Let's suppose we have a class:You can use the following code to obtain the addresses of methods:type TMyClass = class procedure MyProc(const S: String); overload; virtual; procedure MyProc(I : Integer); overload; virtual; end;After optimization, we can get improved versions of the address functions:function MethodAddress1: Pointer; type TMyProc = procedure (const S: String) of object; var P: TMyProc; X: TMyClass; M: TMethod; begin GetMem(Pointer(X), 4); Pointer(Pointer(X)^) := TMyClass; P := X.MyProc; Move(P, M, SizeOf(TMethod)); result := M.Code; FreeMem(Pointer(X), 4); end; function MethodAddress2: Pointer; type TMyProc = procedure (I: Integer) of object; var P: TMyProc; X: TMyClass; M: TMethod; begin GetMem(Pointer(X), 4); Pointer(Pointer(X)^) := TMyClass; P := X.MyProc; Move(P, M, SizeOf(TMethod)); result := M.Code; FreeMem(Pointer(X), 4); end;Now we can registerTMyClass type for paxCompiler:function MethodAddress1_Op: Pointer; type TMyProc = procedure (const S: String) of object; var P: TMyProc; X: TMyClass; M: TMethod; V: TClass; begin V := TMyClass; X := @V; P := X.MyProc; Move(P, M, SizeOf(TMethod)); result := M.Code; end; function MethodAddress2_Op: Pointer; type TMyProc = procedure (I: Integer) of object; var P: TMyProc; X: TMyClass; M: TMethod; V: TClass; begin V := TMyClass; X := @V; P := X.MyProc; Move(P, M, SizeOf(TMethod)); result := M.Code; end;G := RegisterClassType(0, TMyClass); RegisterHeader(G, 'procedure MyProc(const S: String); overload; virtual;', MethodAddress1_Op); RegisterHeader(G, 'procedure MyProc(I : Integer); overload; virtual;', MethodAddress2_Op);