Home > Back-end >  Delphi a word translated into C builder
Delphi a word translated into C builder

Time:09-19

Is studying a thing, but is full of Delphi, a simple line is not complex, translation,
The process also don't know is what, create the event handling method? And what about the variable parameter and so on, in the callmethod,
And translated into c + + builder can compile statements






Especially fsScript1. AddMethod (' procedure DelphiFunc (s: String; I: Integer) ', CallMethod);

This' procedure how to translated into c + + builder??


{the method handler}
The function TForm1. CallMethod (Instance: TObject; ClassType: TClass; Const MethodName: String;
Var Params: the Variant) : the Variant;
The begin
Params DelphiFunc (Params [0], [1]).
end;

procedure TForm1.Button1Click(Sender: TObject);
The begin
{the clear all the items}
FsScript1. The Clear;
{script text}
FsScript1. Lines:=Memo1. Lines;
{frGlobalUnit contains standard types and functions provides}
FsScript1. Parent:=fsGlobalUnit;
{make DelphiFunc procedure visible to a script}
FsScript1. AddMethod (' procedure DelphiFunc (s: a String; I: Integer) ', CallMethod);

{the compile the script}
If fsScript1.Com running then
FsScript1. Execute the else {the Execute the if compilation was succesfull}
ShowMessage (fsScript1 ErrorMsg); {show an error message}
end;
If you want to add several methods, you can do it using one method handler:

Prog. AddMethod (' procedure DelphiFunc (s: a String; I: Integer) ', CallMethod);
Prog. AddMethod (' procedure DelphiFunc2 (s: String) ', CallMethod);

{the method handler}
The function TForm1. CallMethod (Instance: TObject; ClassType: TClass; Const MethodName: String;
Var Params: the Variant) : the Variant;
The begin
{dispatch the method call}
If MethodName='DELPHIFUNC' then
Params DelphiFunc (Params [0], [1])
Else if MethodName='DELPHIFUNC2 then
DelphiFunc2 (Params [0]);
end;

CodePudding user response:

> FsScript1. AddMethod (' procedure DelphiFunc (s: a String; I: Integer) ', CallMethod);
Feel the DelphiFunc signature should be a function pointer

Translated into c + + Builder syntax:
1. The function pointer definition:
Typedef void (* DelphiFunc) (String s, int I);
2. Call the place of usage:
FsScript1 - & gt; AddMethod (DelphiFunc CallMethod);

Also, here is CallMethod TForm1 this function:
The function TForm1. CallMethod (Instance: TObject; ClassType: TClass; Const MethodName: String;
Var Params: the Variant) : the Variant;

CodePudding user response:

This is fastscript Script component, its here with scripts are PascalScript, Delphi grammar, so the translation is not a c + +, but it also supports c + + Script syntax, you want to use the CB fastscript,

CodePudding user response:

Reference; https://www.fast-report.com/en/product/fast-script/
  • Related