Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Is it possible to have RAP function return something from ANOTHER dataset?

edited December 2003 in RAP

TIA to all who dare answer!

Sounds easy enough on the surface, but I have struggled a bit with this
one, and RAP is something that is new to me.

I have created a myRAPFunc.pas unit that initializes all the necessary
code to allow three new functions to be available within the Language
tab successfully. No problems there. I even added DB, ADO and
TBetterADODataset to the uses clause of the myRAPFuncs unit.

ANY and all help will be appreciated. Also, if I am attempting something
that can be done differently, more easily, feel free to make
suggestions.

Thanks in advance.
Cenay' Nailor
Priority, Inc.



myRAPFuncs.pas looks like this...

unit myRAPFuncs;

interface

uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, DB, ADODB, BetterADODataSet, raFunc,
ppRTTI, dmPrice;

type
TmyUDFunction = class (TraSystemFunction)
public
class function Category: String; override;
end;

TmyPubPriceFunction = class (TmyUDFunction)
public
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: String; override;
class function HasParams: Boolean; override;
end;

TmyPostPriceFunction = class (TmyUDFunction)
public
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: String; override;
class function HasParams: Boolean; override;
end;

TmySalesPriceFunction = class (TmyUDFunction)
public
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: String; override;
class function HasParams: Boolean; override;
end;


implementation

{ TmyUDFunction.Category }
class function TmyUDFunction.Category: String;
begin
Result := 'User Defined';
end; {class function Category}

class function TmyPubPriceFunction.GetSignature: String;
begin
Result := 'function PubPrice(nAsapID: Integer): currency;';
end; {class function GetSignature}

class function TmyPostPriceFunction.GetSignature: String;
begin
Result := 'function PostPrice(nAsapID: Integer): currency;';
end; {class function GetSignature}

class function TmySalesPriceFunction.GetSignature: String;
begin
Result := 'function salesPrice(nAsapID: Integer): currency;';
end; {class function GetSignature}

class function TmyPubPriceFunction.HasParams: Boolean;
begin
Result := True;
end; {class function HasParams}

class function TmyPostPriceFunction.HasParams: Boolean;
begin
Result := True;
end; {class function HasParams}

class function TmySalesPriceFunction.HasParams: Boolean;
begin
Result := True;
end; {class function HasParams}


procedure TmyPubPriceFunction.ExecuteFunction(aParams: TraParamList);
var
lpAsapID : Integer;
lsResult : Currency;

lcFeeType : String;
lbIsPrebill : Boolean;

begin

GetParamValue(0, lpAsapID);
lcFeeType := 'Pub';
lbIsPreBill := True;


//:[ Stepping through this code, it bombs here everytime!
try
Price.LUExistingFee.Close;
Price.LUExistingFee.Parameters[0].Value := lpAsapID;
Price.LUExistingFee.Parameters[1].Value := lcFeeType;
Price.LUExistingFee.Parameters[2].Value := lbIsPreBill;
Price.LUExistingFee.Open;
except
end;

if Price.LUExistingFee.Active then
begin
if Price.LUExistingFee.RecordCount = 0 then
lsResult := 0.00
else
lsResult := Price.LUExistingFeeFeeTotal.AsCurrency;
end;
Price.LUExistingFee.Close;

SetParamValue(1, lsResult);

end; {Procedure ExecuteFunction}

procedure TmyPostPriceFunction.ExecuteFunction(aParams: TraParamList);
begin
//:[ Same as above, just sets different parameters
end; {Procedure ExecuteFunction}

procedure TmySalesPriceFunction.ExecuteFunction(aParams: TraParamList);
begin
//:[ Same as above, just sets different parameters
end; {Procedure ExecuteFunction}

initialization

raRegisterFunction('PubPrice', TmyPubPriceFunction);
raRegisterFunction('PostPrice', TmyPostPriceFunction);
raRegisterFunction('SalesPrice', TmySalesPriceFunction);

finalization

raUnRegisterFunction('PubPrice');
raUnRegisterFunction('PostPrice');
raUnRegisterFunction('SalesPrice');

end.

Comments

  • edited December 2003
    You did not mention what you are trying to get from ANOTHER dataset, it
    might be much easier to sign that dataset to a ppPipeLine and access it in
    RAP (if you don't need to manipulate the other dataset, if you have Master
    Detail relationship set etc.).

    -Jack


  • edited December 2003

    You state that the TmyPubPriceFunction.ExecuteFunction method bombs. So lets
    break this method into a couple of simple tests.

    1. Test the RAP class itself. In other words, test the parameter passing and
    the passing of the result back to the report. Here is a modified version of
    the ExecuteFunction method.

    procedure TmyPubPriceFunction.ExecuteFunction(aParams: TraParamList);
    var
    lpAsapID : Integer;
    lsResult : Currency;
    begin

    GetParamValue(0, lpAsapID);

    // check parameter value
    ShowMessage('lpAsapID = ' + IntToStr(lpAsapID));

    // test return value

    lsResult := 251.00;

    SetParamValue(1, lsResult);

    end; {Procedure ExecuteFunction}


    2. Test the DataSet functionality by using some hard coded paremeters. I
    think the DataSet code is the problem. I do not see where you create an
    instance of the Price object. Try tracing this code to see what is invalid.
    Also for testing remove the try..except and let the code raise an exception.
    In the Delphi debugger, set break on Delphi exception to true.





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

    Best regards,

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