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"”
请高手帮忙!
我在程序内如此调用自定义函数:
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"”
请高手帮忙!