3.23 bug fsGlobalUnit is not work
fsGlobalUnit is not work
in 3.18
constructor TfrxReport.Create(AOwner: TComponent);
begin
inherited;
FVersion := FR_VERSION;
FDatasets := TfrxReportDatasets.Create(Self);
FVariables := TfrxVariables.Create;
FScript := TfsScript.Create(nil);
FScript.Parent := fsGlobalUnit;
FScript.ExtendedCharset := True;
in 3.23
constructor TfrxReport.Create(AOwner: TComponent);
begin
inherited;
FVersion := FR_VERSION;
FDatasets := TfrxReportDatasets.Create(Self);
FVariables := TfrxVariables.Create;
FScript := TfsScript.Create(nil);
FScript.ExtendedCharset := True;
FScript.AddRTTI;
unit myfunctions;
interface
implementation
uses SysUtils, Classes, fs_iinterpreter;
type
TFunctions = class (TObject)
private
function CallMethod(Instance: TObject; ClassType: TClass; const
MethodName: String ; var Params: Variant): Variant;
public
constructor Create;
destructor Destroy; override ;
end;
var
Functions: TFunctions;
function MyFunc(s: String ; i: Integer): Boolean;
begin
// necessary logic
end;
procedure MyProc(s: String );
begin
// necessary logic
end ;
{ TFunctions }
constructor TFunctions.Create;
begin
with fsGlobalUnit do
begin
AddedBy := Self;
AddMethod('function MyFunc(s: String; i: Integer): Boolean',
CallMethod, 'My functions', 'The MyFunc function always returns True');
AddMethod('procedure MyProc(s: String)', CallMethod, 'My functions',
'The MyProc procedure does not do anything'');
AddedBy := nil ;
end;
end;
destructor TFunctions.Destroy;
begin
if fsGlobalUnit <> nil then
fsGlobalUnit.RemoveItems(Self);
inherited;
end;
function TFunctions.CallMethod(Instance: TObject; ClassType: TClass;
const MethodName: String ; var Params: Variant): Variant;
begin
if MethodName = 'MYFUNC' then
Result := MyFunc(Params[0], Params[1])
else if MethodName = 'MYPROC' then
MyProc(Params[0]);
end;
initialization
Functions := TFunctions.Create;
finalization
Functions.Free;
end.
in 3.18
constructor TfrxReport.Create(AOwner: TComponent);
begin
inherited;
FVersion := FR_VERSION;
FDatasets := TfrxReportDatasets.Create(Self);
FVariables := TfrxVariables.Create;
FScript := TfsScript.Create(nil);
FScript.Parent := fsGlobalUnit;
FScript.ExtendedCharset := True;
in 3.23
constructor TfrxReport.Create(AOwner: TComponent);
begin
inherited;
FVersion := FR_VERSION;
FDatasets := TfrxReportDatasets.Create(Self);
FVariables := TfrxVariables.Create;
FScript := TfsScript.Create(nil);
FScript.ExtendedCharset := True;
FScript.AddRTTI;
unit myfunctions;
interface
implementation
uses SysUtils, Classes, fs_iinterpreter;
type
TFunctions = class (TObject)
private
function CallMethod(Instance: TObject; ClassType: TClass; const
MethodName: String ; var Params: Variant): Variant;
public
constructor Create;
destructor Destroy; override ;
end;
var
Functions: TFunctions;
function MyFunc(s: String ; i: Integer): Boolean;
begin
// necessary logic
end;
procedure MyProc(s: String );
begin
// necessary logic
end ;
{ TFunctions }
constructor TFunctions.Create;
begin
with fsGlobalUnit do
begin
AddedBy := Self;
AddMethod('function MyFunc(s: String; i: Integer): Boolean',
CallMethod, 'My functions', 'The MyFunc function always returns True');
AddMethod('procedure MyProc(s: String)', CallMethod, 'My functions',
'The MyProc procedure does not do anything'');
AddedBy := nil ;
end;
end;
destructor TFunctions.Destroy;
begin
if fsGlobalUnit <> nil then
fsGlobalUnit.RemoveItems(Self);
inherited;
end;
function TFunctions.CallMethod(Instance: TObject; ClassType: TClass;
const MethodName: String ; var Params: Variant): Variant;
begin
if MethodName = 'MYFUNC' then
Result := MyFunc(Params[0], Params[1])
else if MethodName = 'MYPROC' then
MyProc(Params[0]);
end;
initialization
Functions := TFunctions.Create;
finalization
Functions.Free;
end.
Comments
Try this code:
type
TFunctions = class(TfsRTTIModule)
public
constructor Create(AScript: TfsScript); override;
end;
{ TFunctions }
constructor TFunctions.Create(AScript: TfsScript);
begin
inherited Create(AScript);
with AScript do
begin
AddClass(TfrxTestLabel, 'TfrxDialogControl');
end;
end;
initialization
fsRTTIModules.Add(TFunctions);
end.