Jump to content
ebachs10

Quick-Report - Pointer Error - Composite Report

Recommended Posts

Hi All,

I’m relatively new to Delphi and have recently taken over maintenance of a fairly large application that uses QuickReport extensively.

The project’s architecture leaves some room for improvement, but given its size, I plan to refactor it step by step.

Problem Description:

I need to create a composite QuickReport that includes several reports of the same type, all based on a shared report template. Currently, the application structure includes:

  • A main unit, let’s call it Components_CompositeReport, which orchestrates the reports.

  • For each of the 40 components, there’s a dedicated unit (e.g. ComponentReport1, ComponentReport2, … ComponentReport40), each containing the same QuickReport layout.

Unfortunately, this setup means that any layout change has to be replicated across all 40 units, which is inefficient and error-prone.

Current Structure:

In each unit (e.g. ComponentReportX.pas), the only logic is:

 

var
  aComponentReportFormX: TComponentRptFormX;

function ComponentReportFormX: TComponentRptFormX;
begin
  if not Assigned(aComponentReportFormX) then
    aComponentReportFormX := TComponentRptFormX.Create(nil);
  Result := aComponentReportFormX;
end;
 

For report unit 1 (ComponentReport1), there’s some additional logic to map global data.

In the composite report unit (Components_CompositeReport), the current approach looks like this:

 

if Component1Exists = True then
begin
  ComponentReport(1,1);
  Add(ComponentReport1);  // Add to composite report
end;

if Component2Exists = True then
begin
  ComponentReport(2,2);
  Add(ComponentReport2);  // Add to composite report
end;

// … and so on for each component
 

What I Want:

I’d like to consolidate the design into a single unit containing the QuickReport layout, and instantiate it dynamically for each active component. I tried the following approach:

 

for i := 1 to 40 do
begin
  ComponentForm := TComponentRptForm.Create(nil);
  ComponentReport(i, i, ComponentForm);
  Add(ComponentForm.Report1);
  ComponentForm.Free;
end;
 

However, this results in a pointer error:

---------------------------
Program
---------------------------
Access violation at address 009CA9ED in module 'Program.exe'. Read of address 0000030D.
---------------------------
OK
---------------------------
 

Question:

  • How can I correctly implement a single QuickReport layout that’s reused dynamically for multiple components?

  • What’s causing the access violation error in the code snippet above?

  • Is there a recommended way to structure a dynamic composite QuickReport in Delphi to avoid duplicating the layout across multiple units?

Any guidance or best practices on how to proceed would be greatly appreciated!

Thanks in advance for your help.

 

/Esben

Share this post


Link to post

That looks like the wrong thing to be working on - an unrolled loop vs a loop just isn't a big deal. 

 

Likely separate units so each could be customized but that didn't end up being required. Or some actually are customized by having different properties set for the same base QuickReport layout or in some other way. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×