FastReport giving Access Violation error
Haley Winters
Mosman, Australia
Hi all,
I wanted to ask if I can get some help - I sometimes ask for help on the Embarcadero forum if I get stuck with Delphi but now it looks like I'm really in trouble and it is possibly due to how I am using FastReport.
I have an FDQuery that gives me some results from commands that I can type. The results of the FDQuery are pulled over into an frxDBDataSet and I have two showmessages that indicate that they are populated.
My code below gets up to the ShowMessage('E') and then the frxReport.ShowReport throws up an 'Access violation at address 009BB039 in module cool_program_name. read of address 000000E0'.
Are there any ideas on what might be causing this - the majority of the code is from the FastReport4 code based reports example, is there a way that I can check if the frxDBDataSet has been populated correctly?
BTW - I am writing the program in Delphi XE8 on my Dad's work laptop, everything is completely vanilla.
Best regards,
Haley
procedure TMainForm.mnuPrint_OnExecute(Sender: TObject);
var
frxDBDataSet : TfrxDBDataSet; // Was TfrxDataSet
frxReport : TfrxReport;
//DataPage: TfrxDataPage; // This isn't actually used
Page: TfrxReportPage;
Band: TfrxBand;
DataBand: TfrxMasterData;
Memo: TfrxMemoView;
begin
frxDBDataSet:= TfrxDBDataSet.Create(frxReport.Owner); // Was TfrxDataSet
frxDBDataSet.Name:= 'UserData';
frxDBDataSet.UserName:= Name;
frxDBDataSet.DataSet:= FDQuery;
ShowMessage('Field Count = ' + inttostr(frxDBDataSet.FieldsCount)); // for the sample data this shows 10
ShowMessage('Records Count = ' + inttostr(frxDBDataSet.RecordCount)); // for the sample data this shows 9622
frxReport:= TfrxReport.Create(Self);
frxReport.Clear;
frxReport.EnabledDataSets.Add(frxDBDataSet);
//DataPage := TfrxDataPage.Create(frxReport); // No idea why this was in the example
Page := TfrxReportPage.Create(frxReport);
Page.CreateUniqueName;
Page.SetDefaults;
//Page.Orientation := poLandscape; Doesn't like anything I put in here, I don't actually have a printer
ShowMessage('A');
Band := TfrxReportTitle.Create(Page);
Band.CreateUniqueName;
Band.Top := 0;
Band.Height := 20;
ShowMessage('B');
Memo := TfrxMemoView.Create(Band);
Memo.CreateUniqueName;
Memo.Text := 'This is all the page says!';
Memo.Height := 20;
Memo.Align := baWidth;
ShowMessage('C');
DataBand := TfrxMasterData.Create(Page);
DataBand.CreateUniqueName;
DataBand.DataSet := frxDBDataSet;
DataBand.Top := 100;
DataBand.Height := 20;
ShowMessage('D');
Memo := TfrxMemoView.Create(DataBand);
Memo.CreateUniqueName;
Memo.DataSet := frxDBDataSet;
Memo.DataField := 'CustNo';
Memo.SetBounds(0, 0, 100, 20);
Memo.HAlign := haRight;
//frxReport.PrepareReport(True); // This causes the DBGrid to scroll from top to bottom
//frxReport.Report.ShowPreparedReport; // This creates a blank view - no page at all
ShowMessage('E');
frxReport.ShowReport;
end;
I wanted to ask if I can get some help - I sometimes ask for help on the Embarcadero forum if I get stuck with Delphi but now it looks like I'm really in trouble and it is possibly due to how I am using FastReport.
I have an FDQuery that gives me some results from commands that I can type. The results of the FDQuery are pulled over into an frxDBDataSet and I have two showmessages that indicate that they are populated.
My code below gets up to the ShowMessage('E') and then the frxReport.ShowReport throws up an 'Access violation at address 009BB039 in module cool_program_name. read of address 000000E0'.
Are there any ideas on what might be causing this - the majority of the code is from the FastReport4 code based reports example, is there a way that I can check if the frxDBDataSet has been populated correctly?
BTW - I am writing the program in Delphi XE8 on my Dad's work laptop, everything is completely vanilla.
Best regards,
Haley
procedure TMainForm.mnuPrint_OnExecute(Sender: TObject);
var
frxDBDataSet : TfrxDBDataSet; // Was TfrxDataSet
frxReport : TfrxReport;
//DataPage: TfrxDataPage; // This isn't actually used
Page: TfrxReportPage;
Band: TfrxBand;
DataBand: TfrxMasterData;
Memo: TfrxMemoView;
begin
frxDBDataSet:= TfrxDBDataSet.Create(frxReport.Owner); // Was TfrxDataSet
frxDBDataSet.Name:= 'UserData';
frxDBDataSet.UserName:= Name;
frxDBDataSet.DataSet:= FDQuery;
ShowMessage('Field Count = ' + inttostr(frxDBDataSet.FieldsCount)); // for the sample data this shows 10
ShowMessage('Records Count = ' + inttostr(frxDBDataSet.RecordCount)); // for the sample data this shows 9622
frxReport:= TfrxReport.Create(Self);
frxReport.Clear;
frxReport.EnabledDataSets.Add(frxDBDataSet);
//DataPage := TfrxDataPage.Create(frxReport); // No idea why this was in the example
Page := TfrxReportPage.Create(frxReport);
Page.CreateUniqueName;
Page.SetDefaults;
//Page.Orientation := poLandscape; Doesn't like anything I put in here, I don't actually have a printer
ShowMessage('A');
Band := TfrxReportTitle.Create(Page);
Band.CreateUniqueName;
Band.Top := 0;
Band.Height := 20;
ShowMessage('B');
Memo := TfrxMemoView.Create(Band);
Memo.CreateUniqueName;
Memo.Text := 'This is all the page says!';
Memo.Height := 20;
Memo.Align := baWidth;
ShowMessage('C');
DataBand := TfrxMasterData.Create(Page);
DataBand.CreateUniqueName;
DataBand.DataSet := frxDBDataSet;
DataBand.Top := 100;
DataBand.Height := 20;
ShowMessage('D');
Memo := TfrxMemoView.Create(DataBand);
Memo.CreateUniqueName;
Memo.DataSet := frxDBDataSet;
Memo.DataField := 'CustNo';
Memo.SetBounds(0, 0, 100, 20);
Memo.HAlign := haRight;
//frxReport.PrepareReport(True); // This causes the DBGrid to scroll from top to bottom
//frxReport.Report.ShowPreparedReport; // This creates a blank view - no page at all
ShowMessage('E');
frxReport.ShowReport;
end;