Home RAP

RAP WoY Function

edited January 2009 in RAP
Hi Guys,

Just starting out on this RAP stuff and I'm afraid my skills aren't up to it
yet.

I am trying to create a RAP Week of the Year function i.e. WoY(Date) to give
the Week #. I have taken the 'Trim()' example and tried to convert it.

I have the following which compiles into the application OK but when I go to
open it in 'Calc' it won't 'compile'
===============================================================================
unit myRapFuncs0037;

interface

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

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

implementation

{------------------------------------------------------------------------------}
{ TmyWoYFunction.GetSignature }

class function TmyWoYFunction.GetSignature: String;
begin
Result := 'function WOY(const AValue: TDateTime): Word; overload;';
end; {class function, GetSignature}

{------------------------------------------------------------------------------}
{ TmyWoYFunction.ExecuteFunction }

procedure TmyWoYFunction.ExecuteFunction(aParams: TraParamList);
var
lsResult: Word;
lsDate: TDateTime;
begin

GetParamValue(0, lsDate);

lsResult := WeekofTheYear(lsDate);

SetParamValue(1, lsResult);

end; {procedure, ExecuteFunction}



initialization
raRegisterFunction('WoY', TmyWoYFunction);

finalization
raUnRegisterFunction('WoY');

end.
================================================================================

I have clearly not done it right.

I would appreciate it if someone could point out the error of my ways..

Regards & TIA,

Ian

Comments

  • edited January 2009
    Hi Ian,

    Try removing the "overload" keyword from the declairation of the function
    signature. Note that unless you build this into a design-time package and
    install in into the IDE, your code will only compile at runtime.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2009
    Hi Nard,

    Thanks for the reply.


    I removed the 'overload;' but I still get "Cannot compile signature for
    DateTime function: WOY." at run time when select 'Language'.


    Sorry, I don't understand what you are saying here.

    Regards,

    Ian
  • edited January 2009
    Hi Ian,

    I believe the issue is the "word" type. Rap does not have a concept of this
    type. Try using an Integer type instead and the routine should function
    correctly.

    class function TmyWoYFunction.GetSignature: String;
    begin
    Result := 'function WOY(const AValue: TDateTime): Integer';
    end; {class function, GetSignature}

    {------------------------------------------------------------------------------}
    { TmyWoYFunction.ExecuteFunction }

    procedure TmyWoYFunction.ExecuteFunction(aParams: TraParamList);
    var
    liResult: Integer;
    lDate: TDateTime;
    begin

    GetParamValue(0, lDate);

    lsResult := WeekofTheYear(lDate);

    SetParamValue(1, liResult);

    end; {procedure, ExecuteFunction}


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.