Modifying the variable’s value |
Top Previous Next |
There are two ways to modify the value of a variable:
Pascal:
frxReport1.Variables['My Variable 2'] := 10;
C++:
frxReport1->Variables->Variables["My Variable 2"] = 10;
or
Pascal:
var Index: Integer; Variable: TfrxVariable;
{ search for the variable } Index := frxReport1.Variables.IndexOf('My Variable 2'); { if it is found, change a value } if Index <> -1 then begin Variable := frxReport1.Variables.Items[Index]; Variable.Value := 10; end;
C++:
int Index; TfrxVariable * Variable;
// search for the variable Index = frxReport1->Variables->IndexOf("My Variable 2"); // if it is found, change a value if(Index != -1) { Variable = frxReport1->Variables->Items[Index]; Variable->Value = 10; }
It should be noted, that when accessing a report variable its value is calculated if it is of string type. That means the variable whose value is 'Table1.“Field1”' will return a value of a DB field and not the 'Table1."Field1"' string. You should be careful when assigning a string-type value to a report variable. For example, this code will raise the exception “unknown variable 'test'” when running a report:
frxReport1.Variables['My Variable'] := 'test';
because FastReport is trying to calculate a value for variable 'test'. The right way to pass a string value is:
frxReport1.Variables['My Variable'] := '''' + 'test' + '''';
In this case the variable value, string 'test', will be shown without errors. But keep in mind that: - a string should not contain single quotes : all single quotes must be doubled; - a string should not contain #13 or #10 symbols.
In some cases it is easier to pass variables using a script.
|