Dynamic variables in Reports

edited 10:09AM in FastReport 4.0
Hi

I am fairly new to fast reports. Currently I am using Delphi XE2.

The problem I am having is that I am trying to create a report that will display the dates that I have selected on my form in the header of my report. The format of the dates needs to be 'dd/MM/yyyy'.

I have looked through the Programmers Manual and the User's Manual and none can provide me with the answers.

I have opened the frxReport1 component and then under Report->Variables, I have created a category 'Dates' and then 2 variables 'StartDate' and 'EndDate'. Then back in my main form I assigned values to them like so:
frxReport1.Variables := startdate_dtp.Date;
frxReport1.Variables := enddate_dtp.Date;

I have also tried passing it like so:
frxReport1.Variables := startdate_dtp.Text;
frxReport1.Variables := enddate_dtp.Text;

But when I run my report, with the .Date function it just displays an Interger value, and with the .Text function it display a Decimal value.

How do I get the report to display these dates correctly, as there are many other different types of values (Strings, Integers) that I am going to need to pass to other reports in the future as well.

Thanks

GavinC

Comments

  • fcsfcs
    edited 10:09AM
    Hello,

    Try to use:

    {$H+}
    procedure TForm1.FReport123_GetValue(const VarName: string; var Value: Variant);
    begin
    if VarName='StartDate' then Value:=startdate_dtp.Text;
    if VarName='EndDate' then Value:=enddate_dtp.Text;
    end;
    {H-}

    The H+/- are optional, I use short strings and I have to enable huge strings for these procedure.
    The GetValue function is an event in FastReport report.

    Regards
    Michal
  • gordkgordk St.Catherines On. Canada.
    edited 10:09AM
    You can pass the value the way you are trying with out using the ongetvalue event.
    first look at the type of the value in your form is it a tdatetime value or a formated date string
    if it is a formated date string then you need to add extra string delimiters to pass it to the varaiable.
  • edited 10:09AM
    gordk wrote: »
    You can pass the value the way you are trying with out using the ongetvalue event.
    first look at the type of the value in your form is it a tdatetime value or a formated date string
    if it is a formated date string then you need to add extra string delimiters to pass it to the varaiable.

    I get the date values from a TwwDBDateTimePicker which is from Clever Components, but basically works the same as a normal TDateTimePicker. Now have tried just about every possible combination I can think of to try and manipulate the value, from DateToStr and from StrToDate and still it gives me either a Interger or Decimal value on the report.

    I have also double clicked on the frxReport1 component, and under Report -> Variables, I added a category and 2 variables, and then on the right screen, assigned a Date Function to the variable, but still no luck?

    What else could possibly be going wrong or what else could I try?
  • gordkgordk St.Catherines On. Canada.
    edited 10:09AM
    Gavin the fact that you keep getting an integer tells me that you are passing in
    something that looks like this mm/dd/yyyy so the expression evaluator is doing division.
    dont forget that categorized variables are expressions.her is a tip to help
    empty the variable so it has no value. pass the value into the variable after loading the report
    instead of calling showreport call design report now look at the value of the variable if it is a date string it should have ' delimiters
    'mm/dd/yyyy ' not the above sample
    also check what diplay format the memo object that uses the variable is set to

  • edited May 2015
    gordk wrote: »
    Gavin the fact that you keep getting an integer tells me that you are passing in
    something that looks like this mm/dd/yyyy so the expression evaluator is doing division.
    dont forget that categorized variables are expressions.her is a tip to help
    empty the variable so it has no value. pass the value into the variable after loading the report
    instead of calling showreport call design report now look at the value of the variable if it is a date string it should have ' delimiters
    'mm/dd/yyyy ' not the above sample
    also check what diplay format the memo object that uses the variable is set to

    Thank you very much for the help. I had to use DecodeDate and manipulate the dates in order to display them correctly.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.