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

Days Between To Dates

edited April 2005 in RAP
Delphi has a DaysBetween function where I can get the number of days between
two dates. Is there a way to do the same thing with rap.

Thanks,
Richard Gostin

Comments

  • edited April 2005
    Hi Richard,

    Although RAP does not support the DaysBetween routine, it should be fairly
    simple to calculate the days between two TDateTime types using the Integer
    representation of each type. Subtracting one date from the other in integer
    form will give you the difference in days.

    Also, if you would like to implement a pass thru function, you can manually
    add this functionality to RAP.

    --------------------------------------------------
    Article: Extending RAP
    ---------------------------------------------------

    There are two very simple and powerful techniques to extend the capabilities
    of RAP infinitely. These are summarized below and covered in more detail in
    the RAP.hlp online help. Demos and tutorials are installed to
    RBuilder\Demos\RAP. The tutorial text is located in RAP.hlp.


    1. RAP Pass-Through Functions

    These are functions that appear in the Language tab of RAP's Code Toolbox.
    These functions are written in Delphi and can be called from RAP. RAP's
    pass-through function architecture enable's developers to add new built-in
    functions to RAP's code toolbox.

    2. Extend RAP's RTTI

    RAP's Run-time Type information defines what classes and properties can be
    accessed via RAP. By default the published properties of any class that is
    registered with Delphi's RegisterClass procedure is recognized by RAP. In
    addition many of the public properties and methods of ReportBuilder classes
    are exposed.


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2005
    Richard,

    Here is the RAP Pass-Thru function that we use:

    Add the following to the interface section of the unit:

    type
    TraReturnDaysBetweenDates = class(TraSystemFunction)
    public
    class function Category: string; override;
    procedure ExecuteFunction(aParams: TraParamList); override;
    class function GetSignature: string; override;
    class function HasParams: Boolean; override;
    class function IsFunction: Boolean; override;
    end;

    Add the following the implemenation section of the unit:

    {
    ************************** TraReturnDaysBetweenDates
    ***************************
    }
    class function TraReturnDaysBetweenDates.Category: string;
    begin
    Result:= 'DateTime'
    end;

    procedure TraReturnDaysBetweenDates.ExecuteFunction(aParams: TraParamList);
    var
    iResult: Integer;
    Date1: TDateTime;
    Date2: TDateTime;
    begin
    GetParamValue(0, Date1);
    GetParamValue(1, Date2);

    iResult:= ReturnDaysBetweenDates(Date1,Date2);

    { The return value is the last value in the zero based parameter list }
    SetParamValue(2, iResult);
    end;

    class function TraReturnDaysBetweenDates.GetSignature: string;
    begin
    result := 'function ReturnDaysBetweenDates(Date1, Date2: TDateTime):
    Integer;';
    end;

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

    class function TraReturnDaysBetweenDates.IsFunction: Boolean;
    begin
    Result:= True;
    end;

    Add the following to the initialization section of the unit:

    raRegisterFunction('ReturnDaysBetweenDates', TraReturnDaysBetweenDates);

    I hope this helps.
    Scott


  • edited May 2005
    Oops...

    You will have to make the following change in the
    TraReturnDaysBetweenDates.ExecuteFunction procedure:

    CHANGE:

    iResult:= ReturnDaysBetweenDates(Date1,Date2);

    TO

    iResult:= DaysBetween(Date1,Date2);

    Scott


This discussion has been closed.