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

Month with 28 days or 30

edited January 2011 in General
Hi Guys,
I have created an report, which show 31 fields (1. - 31.) (TppLabel)
another 31 fields (Variable) which show the weekdays (Mo. - So) and 31
another fields (DBText), which show me a value (DB) for each day.

That's my way to find out the weekday for the specific date:

I open the calculation of each field (Variable, 1 to 31) and write:

value := DayOfWeek(EncodeDate(DBPipelineUPlaner_Config['Jahr'],
DBPipelineUPlaner_Config['Monat'], 28 or 1 or 10, etc...));

case value of
1 : value := 'So.';
2 : value := 'Mo.';
3 : value := 'Di.';
4 : value := 'Mi.';
5 : value := 'Do.';
6 : value := 'Fr.';
7 : value := 'Sa.';
end;

Now my question:
How can i check, if the current month has maybe only 28 days or 30 days?
like this:
if month = 28 days then
begin
ppVariable29.Visible := False;
ppVariable30.Visible := False;
ppVariable31.Visible := False;
ppLabel29.Visible := False;
ppLabel30.Visible := False;
ppLabel31.Visible := False;
ppDBLabel29.Visible := False;
ppDBLabel30.Visible := False;
ppDBLabel31.Visible := False;
end
else
if month = 30 days then
...
and so on.

Comments

  • edited January 2011
    Hi David,

    I believe the DateUtils unit contains a routine named DaysInAMonth. See the
    Delphi help for more information.


    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2011
    Am 17.01.2011 14:57, schrieb Nico Cizik (Digital Metaphors):
    Hi Nico, thanks for your answer.
    My problem isn't how to find out the days in a month, but I don't know
    how to use in den Report Calculator (Open my Report --> Right Click on
    one Variable --> Calculations ..
  • edited January 2011
    Hi,
    i found a solution for my problem :-)
    I clicked on "Calc" and chose there my Variable :)
    There I can see the procedure name, too :) and I can add "var" and my
    variables :)
    But now another question. :-)
    You mentioned the routine DaysInAMonth!
    How can I use this routine in Report Builder.
    #####################################################################
    var
    iTage: Integer;
    idTag, idMonat, idJahr: Integer;
    iJahr, iMonat : Integer;
    LetzterTag : TDateTime;
    begin
    value := DayOfWeek(EncodeDate(DBPipelineUPlaner_Config['Jahr'],
    DBPipelineUPlaner_Config['Monat'], 28));
    LetzterTag := EncodeDate(DBPipelineUPlaner_Config['Jahr'],
    DBPipelineUPlaner_Config['Monat']+1, 1) - 1;
    DecodeDate(LetzterTag,idJahr,idMonat,idTag);

    if idTag = 28 then
    begin
    lb29.Visible := False;
    lb30.Visible := False;
    lb31.Visible := False;
    DBlb29.Visible := False;
    DBlb30.Visible := False;
    DBlb31.Visible := False;
    v29.Visible := False;
    v30.Visible := False;
    v31.Visible := False;
    end
    else.....
    ###############################################################

    Instead of use Encode and Decodedate maybe I will be able to use
    DaysInAMonth, but when I write:
    begin ....
    DaysInAMonth(2011, 2);
    ..
    i got the error: Undeclared identifier 'DaysInAMonth'
  • edited January 2011
    Hi David,

    DaysInAMonth is not natively included with RAP. This can easily be worked
    around by creating a RAP passthru function. Take a look at the RAP demos
    located in the \Demos\0. RAP\... directory for examples and the Developer's
    Guide for more information on creating and using passthru functions in RAP.



    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2011
    Hi Nico,
    now i try to create a passthru function for Delphi function (DaysInAMonth).
    I found the correct .pas file. (unit myRapFuncs0031;)
    I want to rewrite in for the DaysInAMonth function.
    But there I got some problems.

    ##################################################################################
    interface

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

    type {I renamed the function into TmyDaysInaMonth..)
    TmyDaysInaMonthFunction = class (TraDateFunction)
    public
    procedure ExecuteFunction(aParams: TraParamList); override;
    class function GetSignature: String; override;
    end;

    implementation


    {------------------------------------------------------------------------------}
    { TmyTrimFunction.GetSignature }
    {also i renamed the gesSignature function..)
    class function TmyDaysInaMonthFunction.GetSignature: String;
    begin {.. signatured the procedure in the GetSignature method.}
    Result := 'function DaysInAMonth(const AYear: Word; const AMonth:
    Word): Word;';
    end; {class function, GetSignature}

    {------------------------------------------------------------------------------}
    { TmyTrimFunction.ExecuteFunction }

    {but here i don't know how to go on.
    What variables must be set? And how to go on? :) }
    {I also read the RBuilder.pdf Documentation about Adding Functions to
    the Code Toolbox}

    procedure TmyDaysInaMonthFunction.ExecuteFunction(aParams: TraParamList);
    var
    lsResult: String;
    lsString: String;
    begin
    GetParamValue(0, lsString);

    lsResult := Trim(lsString);

    SetParamValue(1, lsResult);

    end; {procedure, ExecuteFunction}


    initialization
    raRegisterFunction('Trim', TmyTrimFunction);

    finalization
    raUnRegisterFunction('Trim');

    end.

    ####################################################################################
  • edited January 2011
    Hi David,

    Inside the ExecuteFunction routine you will receive a TraParamList
    parameter. This contains the parameters sent from RAP and allows you to
    assign a return value.

    In your case you have two parameters "AYear" and "AMonth". These parameters
    would correspond to aParams[0] and aParams[1]. Then you would assign your
    return value to aParams[2].
    Inside the ExecuteFunction routine, you want to make a call to the Delphi
    routine DaysInAMonth() to get your return value, not Trim(). :) Also to
    keep things simple, I would use Integer types for the signature rather than
    Words.

    Something like the following...

    { TmyDaysInaMonthFunction.GetSignature }

    class function TmyDaysInaMonthFunction.GetSignature: String;
    begin
    Result := 'function DaysInAMonth(aYear: Integer; aMonth: Integer):
    Integer;';
    end;

    { TmyDaysInaMonthFunction.ExecuteFunction }

    procedure TmyDaysInaMonthFunction.ExecuteFunction(aParams: TraParamList);
    var
    liYear: Integer;
    liMonth: Integer;
    liResult: Integer;
    begin
    GetParamValue(0, liYear); //Get the Year
    GetParamValue(1, liMonth); //Get the Month

    liResult := DaysInAMonth(liYear, liMonth); //Call Delphi

    SetParamValue(2, liResult); //Return value

    end; {procedure, ExecuteFunction}


    initialization
    raRegisterFunction('DaysInAMonth', TmyDaysInaMonthFunction);

    finalization
    raUnRegisterFunction('DaysInAMonth');

    end.


    Regards,

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

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2011
    Hi Nico,
    hmn, he show me an error at line
    iRückgabe := DaysInAMonth(iJahr, iMonat); // . expected but found (
    Can you please give me a solution for this problem?
    Because I tried a lot but nothing worked ...

    Regards David
  • edited January 2011
    Am 23.01.2011 21:23, schrieb David Wolf:



    Good Morning,
    I found out why he show me the error.
    I wrote Days and press Strg + Space:
    ##############################################################
    "unit DaysInAMonth"
    "const DaysPerWeek = 7"
    ... ...
    "function DaysInAYear(const AYear: Word): Word;"
    ...
    ##############################################################

    But there is not listed the function DaysInAMonth ( const Year, Month :
    Word ) : Word;
    He shows only the Unit DaysInAMonth but not the function, but why?


    Regards David
  • edited January 2011
    Hello again :-)
    .. I think this is my last post in this thread ! :D

    This is my solution:
    procedure TmyDaysInMonthFunction.ExecuteFunction(aParams: TraParamList);
    var
    iJahr, iMonat, iRueckgabe: Integer;
    begin
    GetParamValue(0, iJahr);
    GetParamValue(1, iMonat);

    iRueckgabe := DaysInMonth(EncodeDate(iJahr, iMonat, 1));

    SetParamValue(2, iRueckgabe);
    end;



    ... but one question I still have.
    How can I write my function in the calculator "Language - Language
    Toolbox" below "function - DateTime?



    Thank you very much for your help!!!!

    Regards David
This discussion has been closed.