rdsteed / la-pe

Automatically exported from code.google.com/p/la-pe
0 stars 0 forks source link

todo: how to create method/class method as global function #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
todo: how to crete method/class method as global function (without usage global 
pameters)

class procedure TForm1.MyWrite1(S: string);
begin
  System.Write(...
end;

procedure TForm1.MyWrite2(S: string);
begin
  Memo.Lines.Add(...
end;

????:

Compiler.addGlobalFuncFromClass('function VarCreateOLEObject(const ClassName: 
string): Variant;', @TForm1.MyWrite1, TForm1);

Compiler.addGlobalFuncFromObject('function VarCreateOLEObject(const ClassName: 
string): Variant;', @TForm1.MyWrite2);

Original issue reported on code.google.com by pult....@gmail.com on 19 Sep 2011 at 7:11

GoogleCodeExporter commented 8 years ago
ompiler.addGlobalFuncFromClass('class procedure TForm1.MyWrite1(S: string);', 
@TForm1.MyWrite1, TForm1);

Compiler.addGlobalFuncFromObject('function procedure TForm1.MyWrite2(S: 
string);', @TForm1.MyWrite2);

Original comment by pult....@gmail.com on 19 Sep 2011 at 7:12

GoogleCodeExporter commented 8 years ago
Thanks for reporting. Might be useful indeed.

Original comment by niels....@gmail.com on 21 Sep 2011 at 1:03

GoogleCodeExporter commented 8 years ago
I added addGlobalMethod to the repository, which lets you do this:

Compiler.addGlobalMethod('procedure _write(s: string); override;', @MyWrite, 
Form1);

MyWrite still needs to be a wrapping function, as it sends "self" as parameter 
too:

procedure MyWrite(Params: PParamArray);
begin
  with TForm1(Params^[0]) do
    m.Text := m.Text + PlpString(Params^[1])^;
end; 

I do not plan on adding the option to invoke methods for imported functions.

Original comment by niels....@gmail.com on 10 Nov 2011 at 11:28