Still I Have Problem With Adding Custom Functions.
Hi All,
After reading the Manual Help Of FastReport and COPY & PASTE the example of
it ( Manual Help) in my project same as the example source code ,still i have problem and "CallMethod" function doesn't executed,So My Custom Function Doesn't run Too.!!!.
( I Found That with putting one Break-Point in first line of "CallMethod" function. )
I mixed Up.Also I recieve the following error when i press the "Preview" Button in IDE:
Invalid Variant Type Conversion.
I use the following source code as follows:
//
start
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): String;
begin
RESULT :='Test Functions';
end;
{ TFunctions }
constructor TFunctions.Create;
begin
with fsGlobalUnit do
begin
AddedBy := Self;
AddMethod('function MyFunc(s: String; i: Integer): String',
CallMethod, 'My functions', 'The MyFunc function always returns True');
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.
//
end
Please Help me
Thanks in Advance.
Regards.
After reading the Manual Help Of FastReport and COPY & PASTE the example of
it ( Manual Help) in my project same as the example source code ,still i have problem and "CallMethod" function doesn't executed,So My Custom Function Doesn't run Too.!!!.
( I Found That with putting one Break-Point in first line of "CallMethod" function. )
I mixed Up.Also I recieve the following error when i press the "Preview" Button in IDE:
Invalid Variant Type Conversion.
I use the following source code as follows:
//
start
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): String;
begin
RESULT :='Test Functions';
end;
{ TFunctions }
constructor TFunctions.Create;
begin
with fsGlobalUnit do
begin
AddedBy := Self;
AddMethod('function MyFunc(s: String; i: Integer): String',
CallMethod, 'My functions', 'The MyFunc function always returns True');
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.
//
end
Please Help me
Thanks in Advance.
Regards.