Assigning a string variable in BCB 6

edited 11:44PM in FastReport 4.0
Hello,

We are looking for some assistance as to how to assign a value to a string report variable dynamically using C++ Builder. The documentation appears to have an error in it - it shows this example if doing it via script:

frxReport1->Script->Variables->Variables["My Variable"] = "test";

This doesn't compile - if you change to
frxReport1->Script->Variables["My Variable"] = "test";

it compiles but if the variable has already been declared in the script it doesn't work (you get an error about the variable being redefined). It compiles if the variable doesn't already exist, but then how do you reference it in the script? What we are trying to do is just dynamically set the file name of a picture used in a report. The picture will be in our application's installation folder, which we don't know at compile time.

We've also gotten nowhere trying it by using a Report variable. The problem is when the variable is a string (other types are no problem) - the documentation shows some ugly syntax for assigning a string to a report string variable in Pascal but not in C++, and it's not obvious (to us) how to translate to C++.

The Pascal syntax example, from the programmer's manual:
frxReport1.Variables := '''' + 'test' + '''';

C++ syntax?
frxReport1->Variables->Variables["MyStringVariable"] = ???;


Thanks

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 11:44PM
    I am not a c coder but i will try to shed some light on passing string values into categorized variables.
    A categorized variable is treated as an expression unless the string value is enclosed in
    string delimiters once inside the report (it then triggers the expression parser to try to resolve it
    by triggering the reports ogv event if it can't),
    so when you try to pass the string value in, delimiters get stripped so you need extra ones.
    pacal code
    frxReport1.Variables := '''' + 'test' + '''';


    when you try to add or modify categorized variables from code, the report file(if not storing in dfm) needs to be loaded first.
  • gpigpi
    edited 11:44PM
    Try
    frxReport1->Variables->Variables["My Variable"] = "\"test\"";

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.