Home RAP

RAP Pass-Through Functions/Procedures

edited November 2003 in RAP
Hi

Can anyone help what am I doing wrong so that I can kick myself.

Have been trying to get my functions needed for my reports to appear in
rap however I can never get them to work and can not find any examples
with in the given ones that explain how to do multiple parameter
passing. rapLeftStr Seems to crash with invalid variant type
conversions.

My code is below


type
TmyJSLFunction = class (TraSystemFunction)
public
{Override Category to return a new category string}
class function Category: String; override;
end;

TmyLeftStrFunction = class (TmyJSLFunction)
public
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: String; override;
end;

TmyInStrFunction = class (TmyJSLFunction)
public
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: String; override;
end;


implementation

Uses Utils;

{***********************************************************************
*******
*
** F I L E N A M E F U N C T I O N
*
{***********************************************************************
*******}

{-----------------------------------------------------------------------
-------}
{ TmyFilenameFunction.Category }

class function TmyJSLFunction.Category: String;
begin
Result := 'JSL';
end; {class function Category}


{*****************************
** LeftStr F U N C T I O N
{*****************************}

class function TmyLeftStrFunction.GetSignature: String;
begin
Result := 'function rapLeftStr(vWork : String; iChars : Integer) :
String;';
end; {class function, GetSignature}

{ TmyLeftStr.ExecuteFunction }

procedure TmyLeftStrFunction.ExecuteFunction(aParams: TraParamList);
var
lsResult: String;
sWork,sChars: String;
iChars: Integer;
begin
aParams.GetParamValue(0,sWork);
aParams.GetParamValue(1,iChars);
lsResult := LeftStr(sWork,iChars);

{*** Return Result Back To Report ***}
aParams.SetParamValue(2, lsResult);
end; {procedure, ExecuteFunction}

{-----------------------------------------------------------------------
-------}

{*****************************
** InStr F U N C T I O N
{*****************************}

{-----------------------------------------------------------------------
-------}
{ TmyInStrFunction.GetSignature }

class function TmyInStrFunction.GetSignature: String;
begin
Result := 'function rapInStr(iStart : Integer; sSearchIn : String;
sSearchFor : String) : Integer;';
end; {class function, GetSignature}

{ TmyInStrFunction.ExecuteFunction }

procedure TmyInStrFunction.ExecuteFunction(aParams: TraParamList);
var
liResult: Integer;
iStart: Integer;
sSearchIn: String;
sSearchFor: String;
begin
aParams.GetParamValue(0, iStart);
aParams.GetParamValue(1, sSearchIn);
aParams.GetParamValue(2, sSearchFor);
liResult := InStr(iStart,sSearchIn,sSearchFor);

{**** Return Result Back To Report ***}
SetParamValue(3, liResult);
end; {procedure, ExecuteFunction}
{-----------------------------------------------------------------------
-------}


initialization
raRegisterFunction('RapLeftStr', TmyLeftStrFunction);
raRegisterFunction('RapInStr', TmyInStrFunction);

Comments

  • edited November 2003
    You should override another class function HasParam and return the result :=
    True as well.

    William

  • edited December 2003
    ??? sorry how do you mean?

    new to rap func passing was messing around when I done this was
    surprised to see it appear on the rap list but it did to my surprise.

    Could you please give me a little example, sorry for a slow reply have
    only just got back on to the code.

    Thanks for your help
    Lee

  • edited December 2003

    Actually overriding HasParams is not necessary for your custom functions.
    The ancestorTraSystemFunction defaults this class function to return True.
    You only need to override it, if you implement a function that does not
    return a result.

    Using RB 7.03, I copied your code to a new unit that I added to the
    RBuilder\Demos\RAP\Tutorials\rapTutorials.dpr project. I was able to get the
    rapLeftStr function to work using your code unchanged. I think I added
    StrUtils to the uses clause to get it to compile and I had to comment some
    code in the rapInStr functino, but that is the only changes I made..

    To test the rapLeftStr functino I added a TppVariable to the custom list
    report and in the TppVariable.OnCalc I coded:

    Value := rapLeftStr(plCustomer['Company'], 1);



    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.