『FastReport 3。09 自定义函数的问题,急死人,请高手帮忙!!』 ( 积分: 200 )

  • 主题发起人 主题发起人 skidrow
  • 开始时间 开始时间
S

skidrow

Unregistered / Unconfirmed
GUEST, unregistred user!
FastReport 3。09 中调用自定义函数问题?
我在程序内如此调用自定义函数:
function TForm1.myfun(): String;
begin
Result:='AAA';
end;

function TForm1.frxReport1UserFunction(const MethodName: String;var Params: Variant): Variant;
begin
if MethodName='MYFUN' then
Result:=MyFun();

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
frxReport1.LoadFromFile('q.fr3');
frxReport1.AddFunction('MYFUN:String');
frxReport1.ShowReport(true);(如果这句改成frxReport1.DesignReport;则在设计窗口,看到MYFUN已经在函数列表里)
end;

参考手册是这么讲的:
Way 2:
『function TForm1.MyFunc(s: String ;
i: Integer): Boolean;

begin

// necessary logic
end;

procedure TForm1.MyProc(s: String );

begin

// necessary logic
end;

function TForm1.frxReport1UserFunction( 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;

frxReport1.AddFunction('function MyFunc(s: String;
i: Integer): Boolean');

frxReport1.AddFunction('procedure MyProc(s: String)');

This way is a little easier. Functions' descriptions are now added via the “TfrxReport.AddFunction” method with a single parameter. Functions' call is realized in the TfrxReport.OnUserFunction event's handler.

但只要一运行就错。“Memo1:Error in expression 'MYFUN':Undeclared identfier:"MYFUN"”
请高手帮忙!
 
FastReport 3。09 中调用自定义函数问题?
我在程序内如此调用自定义函数:
function TForm1.myfun(): String;
begin
Result:='AAA';
end;

function TForm1.frxReport1UserFunction(const MethodName: String;var Params: Variant): Variant;
begin
if MethodName='MYFUN' then
Result:=MyFun();

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
frxReport1.LoadFromFile('q.fr3');
frxReport1.AddFunction('MYFUN:String');
frxReport1.ShowReport(true);(如果这句改成frxReport1.DesignReport;则在设计窗口,看到MYFUN已经在函数列表里)
end;

参考手册是这么讲的:
Way 2:
『function TForm1.MyFunc(s: String ;
i: Integer): Boolean;

begin

// necessary logic
end;

procedure TForm1.MyProc(s: String );

begin

// necessary logic
end;

function TForm1.frxReport1UserFunction( 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;

frxReport1.AddFunction('function MyFunc(s: String;
i: Integer): Boolean');

frxReport1.AddFunction('procedure MyProc(s: String)');

This way is a little easier. Functions' descriptions are now added via the “TfrxReport.AddFunction” method with a single parameter. Functions' call is realized in the TfrxReport.OnUserFunction event's handler.

但只要一运行就错。“Memo1:Error in expression 'MYFUN':Undeclared identfier:"MYFUN"”
请高手帮忙!
 
大富翁现在怎么这么浮躁?
 
frxReport1.LoadFromFile('q.fr3');
frxReport1.AddFunction('function MYFUN:String');
frxReport1.ShowReport(true);(
 
不行的,我通过这个方法成功了,可是对OnUserfunction这个方法怎么都不行。
uses fs_iinterpreter;

function TForm1.MyFunc(s: String ;
i: Integer): Boolean;

begin

// necessary logic
end;

procedure TForm1.MyProc(s: String );

begin

// necessary logic
end;

function TForm1.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;

fsGlobalUnit.AddMethod('function MyFunc(s: String;
i: Integer): Boolean', CallMethod);

fsGlobalUnit.AddMethod('procedure MyProc(s: String)', CallMethod);

不过还是谢谢你!
 
后退
顶部