"Invalid Template Format" Error
Hi,
I tried to use your "Tech Tip: Storing Custom Information with Templates",
but after I try to load a report an "Invalid Template Format" error is being
raised. That is considering that all my custom information is being saved
and retrieved correctly. It is just that report loading fails.What could be
the reason?
All I do is the following:
TTemplateInfo = record
SQLQuery: array[1..64] of String[255]; //16384 bytes = 16KB.
end;
procedure DoOnLoadStart(Sender: TObject; Stream: TStream);
procedure DoOnSaveEnd(Sender: TObject; Stream: TStream);
procedure TReportComponentsDialog.FormCreate(Sender: TObject);
begin
inherited;
rbReport.Template.Format:=ftASCII;
rbReport.Template.Offset:=SizeOf(TTemplateInfo);
rbReport.Template.OnNew:=DoOnNew;
rbReport.Template.OnLoadStart:=DoOnLoadStart;
rbReport.Template.OnSaveEnd:=DoOnSaveEnd;
end;
procedure TReportComponentsDialog.DoOnLoadStart(Sender: TObject; Stream:
TStream);
Var
TemplateInfo :TTemplateInfo;
begin
Stream.Seek(0, soFromBeginning);
Stream.Read(TemplateInfo, SizeOf(TTemplateInfo));
ReportSqlListDialog.LoadData(TemplateInfo); //Actualy uses retrived data
end;
procedure TReportComponentsDialog.DoOnSaveEnd(Sender: TObject; Stream:
TStream);
Var
TemplateInfo :TTemplateInfo;
begin
Stream.Seek(0, soFromBeginning);
TemplateInfo:=ReportSqlListDialog.GetData; //Collects all necessary data
for storing.
Stream.Write(TemplateInfo, SizeOf(TTemplateInfo));
end;
I tried to use your "Tech Tip: Storing Custom Information with Templates",
but after I try to load a report an "Invalid Template Format" error is being
raised. That is considering that all my custom information is being saved
and retrieved correctly. It is just that report loading fails.What could be
the reason?
All I do is the following:
TTemplateInfo = record
SQLQuery: array[1..64] of String[255]; //16384 bytes = 16KB.
end;
procedure DoOnLoadStart(Sender: TObject; Stream: TStream);
procedure DoOnSaveEnd(Sender: TObject; Stream: TStream);
procedure TReportComponentsDialog.FormCreate(Sender: TObject);
begin
inherited;
rbReport.Template.Format:=ftASCII;
rbReport.Template.Offset:=SizeOf(TTemplateInfo);
rbReport.Template.OnNew:=DoOnNew;
rbReport.Template.OnLoadStart:=DoOnLoadStart;
rbReport.Template.OnSaveEnd:=DoOnSaveEnd;
end;
procedure TReportComponentsDialog.DoOnLoadStart(Sender: TObject; Stream:
TStream);
Var
TemplateInfo :TTemplateInfo;
begin
Stream.Seek(0, soFromBeginning);
Stream.Read(TemplateInfo, SizeOf(TTemplateInfo));
ReportSqlListDialog.LoadData(TemplateInfo); //Actualy uses retrived data
end;
procedure TReportComponentsDialog.DoOnSaveEnd(Sender: TObject; Stream:
TStream);
Var
TemplateInfo :TTemplateInfo;
begin
Stream.Seek(0, soFromBeginning);
TemplateInfo:=ReportSqlListDialog.GetData; //Collects all necessary data
for storing.
Stream.Write(TemplateInfo, SizeOf(TTemplateInfo));
end;
This discussion has been closed.
Comments
The cause is the following: At the Template field in the database only my
custom information is saved.
So when it tries to load the report this exception is raised.
The question is WHY DOES IT SAVE MY CUSTOM INFORMATION ONLY???
It is supposed to save my information AND report definition. Am I wrong?
Can you help me with it?
Thanks,
MB.
ONLY. For database I need to use database fields.
But. WHY CAN'T I USE THIS METHOD WITH DATABASES AS WELL???
It is the only solution that can be applied for me. Can I somehow store
custom information in the database fields?
The reason for this is because the easiest way to transfer the report from
one database to another is through *.rtm file. But if I have some report
parameters I can only transfer it within the file itself.
Just for that I need to have my parameters within the report, which means
within Template field. So the question is how to save and load custom
information from/to database Template field?
Thanks,
MB.
supported on file based templates. For database templates, use another field
on the database. This is mentioned in the first part of the article from the
Tech-Tips newsgroup in the Templates thread:
-----------------------------------------------------
Tech Tip: Storing Custom Information with Templates
-----------------------------------------------------
Question:
---------
How can I store descriptive information with my report template?
Solution:
---------
1. If you are storing the templates to a database, then you can use the
Report.Template.OnSaveEnd and OnLoadEnd events to store and load the
custom information to appropriate data fields for the record. (This is
the technique used by the ReportExplorer.)
2.....
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com