How do I pass variable from mainprg to frxCrossView
Hi,
How do I pass variables from my Delphi "mainprogram" to the eventhandler "OnPrinCell" in frxCrossViev. I try to use a variable telling the "OnPrinCell" event how to color the individual cells in my Cross Grid but when I want to compile I get an error message telling that the variable is unknown. I have put my MainUnit in the uses row in the start of ReportUnit.
Any solutions?
BR
Lars
Piece of code in the "OnPrintCell" event handler:
for col:= 0 to 11 do begin
for row:= 0 to 31 do begin
Memo.Color:= Dato[col,row].Color;
end;
end;
How do I pass variables from my Delphi "mainprogram" to the eventhandler "OnPrinCell" in frxCrossViev. I try to use a variable telling the "OnPrinCell" event how to color the individual cells in my Cross Grid but when I want to compile I get an error message telling that the variable is unknown. I have put my MainUnit in the uses row in the start of ReportUnit.
Any solutions?
BR
Lars
Piece of code in the "OnPrintCell" event handler:
for col:= 0 to 11 do begin
for row:= 0 to 31 do begin
Memo.Color:= Dato[col,row].Color;
end;
end;
Comments
My project has a variable called Dato[0..23, 0..31] containing the data for a calendar year.
I use Dato in the TfrxReport's OnBeforePrint handler like this
procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
var
Cross: TfrxCrossView;
col, row: Integer;
begin
if Sender is TfrxCrossView then begin
Cross := TfrxCrossView(Sender);
for col := 1 to 12 do begin
for row := 1 to 32 do begin
Cross.AddValue([row],[col], [Dato[col-1,row-1].Tekst]);
end;
end;
end;
end;
In this way my grid on the Report is filled with the correct string (= Dato[...].Tekst) and it functions as I expect-
But when I want to modify the colors of the individual cells by using Dato variable in the frxCrossView's OnPrintCell handler, the the Dato variable is not recognized by the compiler and I get an error message: Undeclared identifier: "Dato"
Is it not possible to use a variable in a Delphi-project inside the frxCrossView's OnPrintCell Eventhandler???
Probably som fundamental issue here I have misunderstood?? Are the Event Handlers "inside" the TfrxReport not able to "see" the variables in the mainproject?
Hope you understand the problem - answer very much appreciated here...
[topic="7588"]Pass variable from Delphi to report[/topic]
Regards
Mick
But now I know that the OnPrintCell handler is not able to see the variable from my Delphi program. This variable has to be "sent" to FR via a custom function (see "Using Custom Functions in a Report" in the Developers Manual page 37).
My problem is that I need a code example showing me exactly how a variable name can be passed to the FastReport and used. At least the people from "FastReport" should be able to help on this subject. It would be fine if the Demo files in the future included an example of this.
The topic I found was just about how to pass a "text" from Delphi into a report variable one can read from a script of running report.
Did you try to compile that or something similar?
Try to pass a string variable as in the topic I mentioned, and include your data in this string in such a way that you'll be able to manipulate it in FR script.
I guess you need to pass some numbers to color your calendar cells. So the string may looks like:
Sat, Sun, Mon, ...
1,1,clRed;1,2,clRed;1,3,clNone;1,4,clNone;1,5,clNone;1,6,clNone;1,7,clRed;....
If I couldn't get any solution (but I do agree there must be a simple method to do so) I would:
- create a temporary table in my database,
- fill it with a series of data I need to pass,
- create an ADOQuery in a report to read from that table,
- use this query in OnPrintCell event,
But if you need to color weekend days you may find a DayOfWeek using an FR function in a OnPrintCell event script.
PS.
Unlike others - I don't use Delphi, so I'm sorry if my posts only takes your time :-(
Regards
Mick
You do not take my time Mick! You have been very helpfull. I'm just a little frustrated about not having an instruction which brings me a solution. That's all.
So far I have solved my problem by adding a small prefix to my Dato[col,row].Tekst coding for the color.
Afterwards removing by only copying the string from the fourth character, like "(y)Ascension" becoming "Ascension". It works and is very simple.
But having purchased FastReport I would like to learn more about it, and I am sorry to tell the guy's from FastReport that concerning this "Custom function" issue the documentation is not good enough.
Best Regards (and thank you)
frxReport1.Script.AddVariable('WPath', 'String', 'c:\windows');
the above was called from Delphi procedure and I think it passes a variable (named WPath) that might be seen from report script.
Regards
Mick