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

Import RoundTo into Report Builder

edited April 2011 in RAP
Hi Guys,
i try to import the function RoundTo via RAP into Report Builder, but it
does not work.

When I have compiled my program and open the Report, I chance into the
calculation tab and open the tab Language and got an error.

Error Code: "Cannot compile Signature for Zeichenkette function: RoundTo"

Here my Source Code for the import:
unit Import;

interface

uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Math, raFunc, ppRTTI, raIDE, DateUtils;

type
TmyRoundToFunction = class (TraStringFunction)
public
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: String; override;
end;

implementation

{------------------------------------------------------------------------------}
{ TmyRoundToFunction.GetSignature }

class function TmyRoundToFunction.GetSignature: String;
begin
Result := 'function RoundTo(const AValue: Extended; const ADigit:
TRoundToEXRangeExtended): Extended;';
end;

{------------------------------------------------------------------------------}
{ TmyRoundToFunction.ExecuteFunction }

procedure TmyRoundToFunction.ExecuteFunction(aParams: TraParamList);
var
AValue, varRueckgabe: Extended;
ADigit: TRoundToEXRangeExtended;
begin
GetParamValue(0, AValue);
GetParamValue(1, ADigit);

varRueckgabe := RoundTo(AValue, ADigit);

SetParamValue(2, varRueckgabe);

end;

initialization
raRegisterFunction('RoundTo', TmyRoundToFunction);

finalization
raUnRegisterFunction('RoundTo');

end.

Are there any problems with the data typs (TRoundToEXRangeExtended) or
where is the problem?




Another question: How can I use functions from delphi in designtime mode.

Comments

  • edited April 2011
    Hi David,

    You are correct, RAP is not going to be able to resolve the
    TRoundToEXRangeExtended type. Perhaps try using a simpler type (String
    or Integer) and convert to the TRoundToEXRangeExtended type inside the
    Execute routine.


    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2011
    Hi Nico,
    can you please give me some source code, because I don't know how to do
    this.

    Regards, David
    Am 11.04.2011 15:16, schrieb Nico Cizik (Digital Metaphors):
  • edited April 2011
    Here my solution:

    Uses
    SysUtils, raFunc, ppRTTI, Math;

    type
    TmyRoundToFunction = class(TraSystemFunction)
    public
    class function Category: string; override;
    procedure ExecuteFunction(AParams: TraParamList); override;
    class function GetSignature: string; override;
    end;

    implementation

    class function TmyRoundToFunction.Category: string;
    begin
    Result := 'Crystal Reports';
    end;

    procedure TmyRoundToFunction.ExecuteFunction(AParams: TraParamList);
    var
    AValue: Extended;
    AResult: Extended;
    ATempDigit: Integer;
    ADigit: TRoundToEXRangeExtended; // [-20 .. 20]
    begin
    GetParamValue(0, AValue);
    GetParamValue(1, ATempDigit);
    try
    ADigit := ATempDigit; // prüfen auf TRoundToEXRangeExtended
    AResult := RoundTo(AValue, ADigit);
    SetParamValue(2, AResult);
    except
    raise Exception.Create('ADigit ist kein TRoundToEXRangeExtended');
    end;
    end;

    class function TmyRoundToFunction.GetSignature: string;
    begin
    Result := 'function RoundTo(const AValue: Extended; const ADigit:
    Integer): Extended;';
    end;

    initialization
    raRegisterFunction('RoundTo', TmyRoundToFunction);

    finalization
    raUnRegisterFunction('RoundTo');

    end.
This discussion has been closed.