Assigning a string variable in BCB 6
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
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
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.
frxReport1->Variables->Variables["My Variable"] = "\"test\"";