Home RAP

Call Delphi function From RAP

edited August 2003 in RAP
Hi

how i can call Delphi function from RAP and assigned the Result value to
Variable

for example

i have Delphi function

function GetZipCode(const City, St, StNum: string): string
begin
...
end;



how to call this function From RAP ???

Thanks

Comments

  • edited August 2003
    RAP has a pass through function capability. Basically, it is a class that is
    compiled and then it allows you to make a call in RAP that calls your new
    class code which makes the Delphi method call. There are tutorials and
    examples in the RAP help file and also in the developer's guide pdf and in
    the RBuilder\Demos\RAP folder. The parameters are also able to be handled.
    Here is a RAP pass through function that takes a TppReport object as a
    parameter and returns the top margin in microns.

    type
    TdmTopMarginInMicrons = class(TraSystemFunction)
    public
    class function Category: String; override;
    class function GetSignature: String; override;
    class function HasParams: Boolean; override;

    procedure ExecuteFunction(aParams: TraParamList); override;
    end;

    implementation

    {Top}

    class function TdmTopMarginInMicrons.Category: String;
    begin
    Result := 'DrawCommandMeasurements';
    end;

    procedure TdmTopMarginInMicrons.ExecuteFunction(aParams: TraParamList);
    var
    lReport: TppReport;
    liMargin: Integer;
    begin

    GetParamValue(0, lReport);

    liMargin := lReport.PrinterSetup.PageDef.mmMarginTop;

    SetParamValue(1, liMargin);

    end;

    class function TdmTopMarginInMicrons.GetSignature: String;
    begin
    Result := 'function TopMarginInMicrons(Report: TppReport): Integer;';
    end;

    class function TdmTopMarginInMicrons.HasParams: Boolean;
    begin
    Result := True;
    end;

    initialization
    raRegisterFunction('TopMarginInMicrons', TdmTopMarginInMicrons);

    finalization
    raUnRegisterFunction('TopMarginInMicrons');


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited August 2003
    Thanks
    i have more 1 question...

    i can add my custom function to the report only at runtime (with the
    Designer Component) ?
    because when the application is in design time the function is not
    registered (initialization Section)

  • edited August 2003
    You'll have to compile the RAP pass through functions into the app. The only
    way to make this dynamic so you wouldn't have to recompile the app everytime
    you wanted to add pass through functions would be to add a hot swapable
    package architecture. The packages would include the pass through function
    classes and registration calls. Delphi can do this and there are usually
    topics like this out on the web. I remember Mark Miller put on a good show
    about this topic at BorCon (Long Beach, Ca. IIRC) a couple of years ago
    called Building Dynamic Applications.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.