Template.LoadFromFile suspends
Hi,
I'm making some tests with ppReport.Template.LoadFromFile as follows:
if ppReport1.Template.FileName <> '' then
try
ppReport1.Template.LoadFromFile;
except
on E: Exception do
begin
Errorbox(E.Message);
Exit;
end;
end;
ppReport1.PrintToDevices;
It works very well. But if the end-user selects a file with a
wrong format (not .rtm file or damaged .rtm) the load
method raises an exception. One can see the Errorbox,
but then the program suspends anywhere.
Please tell me, how is the right error handling for such cases.
Thanks in advance.
Michael
--
D5 Enterprise, RB Enterpise 6.03
I'm making some tests with ppReport.Template.LoadFromFile as follows:
if ppReport1.Template.FileName <> '' then
try
ppReport1.Template.LoadFromFile;
except
on E: Exception do
begin
Errorbox(E.Message);
Exit;
end;
end;
ppReport1.PrintToDevices;
It works very well. But if the end-user selects a file with a
wrong format (not .rtm file or damaged .rtm) the load
method raises an exception. One can see the Errorbox,
but then the program suspends anywhere.
Please tell me, how is the right error handling for such cases.
Thanks in advance.
Michael
--
D5 Enterprise, RB Enterpise 6.03
This discussion has been closed.
Comments
finally gets it right:
procedure TForm1.Button1Click(Sender: TObject);
begin
FCount := 0;
AskUserForReport;
ppReport1.Print;
end;
procedure TForm1.AskUserForReport;
begin
Inc(FCount);
if (FCount = 5) then
LoadReport('C:\GoodTemplates\123.rtm') {good}
else
LoadReport('C:\RBldr\ppReport.pas'); {bad}
end;
procedure TForm1.LoadReport(const aFile: String);
begin
try
ppReport1.Template.FileName := aFile;
ppReport1.Template.LoadFromFile;
except on E: Exception do
AskUserForReport;
end;
end;
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
I've built up an application and placed a Button1Click event exact like you've
shown. It doesn't work. The program suspends. Maybe we should discuss the
other conditions: I have a StringGrid with data in 10 columns and 50 rows. I
use a JITPipeline for connect. I create the fields dynamically, as shown
below. I give you the whole story. Sorry for the length of the script (130
code lines). But this is the complete program. I don't use special own units.
And I only have a StringGrid, a JITPipeline, a ppReport, a ppDesigner to
produce a good template and two buttons placed in my formular Form1.
Please help.
...
implementation
{$R *.DFM}
procedure TForm1.FormShow(Sender: TObject);
procedure PopulateStringGrid;
var
c, r: Integer;
d: Double;
begin
Randomize;
with grdData do
begin
for c := 0 to ColCount - 1 do Cols[c].Clear;
ColCount := 10;
RowCount := 50;
FixedCols := 1;
FixedRows := 1;
DefaultColWidth := 100;
DefaultRowHeight := 17;
// Captions
for r := 1 to RowCount - 1 do
Cells[0, r] := Format('test%3.3d', [r]);
for c := 0 to ColCount - 1 do
Cells[c, 0] := 'Col_' + Format('%.3d', [c]);
// Data
for c := 1 to ColCount - 1 do
for r := 1 to RowCount - 1 do
begin
d := random(10000000) / (random(100) + 1);
Cells[c, r] := FormatFloat('0.00', d);
end;
end;
end;
procedure CreateJITFields;
var
c: Integer;
fld: TppField;
begin
for c := 0 to grdData.ColCount - 1 do
begin
fld := TppField.Create(Self);
fld.FieldName := grdData.Cells[c, 0];
if c > 0 then
begin
fld.DataType := dtDouble;
fld.DisplayFormat := '0.00';
end; // else dtString;
ppJITPipeline1.AddField(fld);
end;
end;
begin
PopulateStringGrid;
CreateJITFields;
ppJITPipeline1.InitialIndex := 1;
ppJITPipeline1.RecordCount := grdData.RowCount - 2;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ppJITPipeline1.FreeFields;
end;
function TForm1.ppJITPipeline1GetFieldValue(aFieldName: string): Variant;
var
c: Integer;
begin
for c := 0 to grdData.ColCount - 1 do
if grdData.Cells[c, 0] = aFieldName then
begin
if c = 0 then
Result := grdData.Cells[c, ppJITPipeline1.RecordIndex]
else
Result := StrToFloat(grdData.Cells[c, ppJITPipeline1.RecordIndex]);
Exit;
end;
end;
procedure TForm1.btnDesignerClick(Sender: TObject);
begin
ppDesigner1.ShowModal;
end;
procedure TForm1.btnAskUserForReportClick(Sender: TObject);
begin
FCount := 0;
AskUserForReport;
ppReport1.Print;
end;
procedure TForm1.AskUserForReport;
var
sPath: string;
begin
inc(FCount);
sPath := ExtractFilePath(Application.ExeName);
if (FCount = 5) then
LoadReport(sPath + 'test_good.rtm')
else
LoadReport(sPath + 'test_bad.rtm');
end;
procedure TForm1.LoadReport(const aFile: string);
begin
try
ppReport1.Template.FileName := aFile;
ppReport1.Template.LoadFromFile;
except
on E: Exception do
begin
AskUserForReport;
end;
end;
end;
end.
That's all. The progam hangs up by "btnAskUserForReportClick".
"test_good.rtm" was built with the designer and "test_bad.rtm" was created by
copy a delphi source file.
If I only load the file ""test_good.rtm"" the program works well.
Thanks in advance.
Michael
except. Add ppTypes to your uses clause.
Looks like the pipeline is instantiated and its fields are getting created,
as the good report works. Change your library path to RBuilder\Source and
trace into it to see where it hangs, or you can send your sample program to
support@digital-metaphors.com and we'll run it.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com