其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
How to use own function?

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

Use TfrReport.OnUserFunction event. Here is simple example:

   procedure TForm1.frReport1UserFunction(const Name: String;
     p1, p2, p3: Variant; var val: Variant);
  begin
    ifAnsiCompareText('SUMTOSTR', Name) = 0then
       val := My_Convertion_Routine(frParser.Calc(p1));
  end;

   After this, you can use SumToStr function in any place of report (in any expression or script).

(ok, but it works only for one TfrReport component. I want to use my function everywhere (in all TfrReport components).

Make OnUserFunction event handler common for all components. If you can't do this, you should create function library:

 
  type
     TMyFunctionLibrary = class(TfrFunctionLibrary)
     public
       constructor Create; override;
       procedure DoFunction(FNo: Integer; p1, p2, p3: Variant;
         var val: Variant); override;
    end;

   constructor MyFunctionLibrary.Create;
   begin
     inherited Create;
     with List do
     begin
       Add('DATETOSTR');
       Add('SUMTOSTR');
     end;
   end;

   procedure TMyFunctionLibrary.DoFunction(FNo: Integer;
     p1, p2, p3: Variant; var val: Variant);
   begin
     val := 0;
     case FNo of
       0: val := My_DateConvertion_Routine(frParser.Calc(p1));
       1: val := My_SumConvertion_Routine(frParser.Calc(p1));
     end;
   end;

   To register function library, call
   frRegisterFunctionLibrary(TMyFunctionLibrary);
To unregister library, call
   frUnRegisterFunctionLibrary(TMyFunctionLibrary);

(how I can add my function to function list (in expression builder)?

Use frAddFunctionDesc procedure (FR_Class unit):

  frAddFunctionDesc('SUMTOSTR', 'My functions',
    'SUMTOSTR()/Converts number to its verbal presentation.');

   Note: "/" symbol is required! It separates function syntax from its description.
FuncLib is reference to your function library (can be nil if you don't use the function library). When function library is unregistered, all its function will be automatically removed from the function list.




相关文章

相关软件