Board index » delphi » QR gives violation error when running for the second time

QR gives violation error when running for the second time

Hi,
  I'd built a report using QR3.0.5 & D5E. My report is executed by a 2nd
level form (meaning it is Main parent's child's child form). I have the
following to print my report:

procedure PrintReport;
begin
  if (CurrentRecord <> -1) then
  begin
    MyReport.Free;
    // I'd reintroduce the constructor to pass in the record number
    MyReport := TMyReport.Create(Self,CurrentRecord);
    MyReport.Preview;
  end;
end;

  The first execution proves fine. When I click on my print button again
(which runs the procedure), or exit out, open another record and runs print
again, it gives me an access violation error.
  Since it halted at the Free line, I thought there's a bug there. I
modified that line to detect whether there was a report previously create:

  if Assigned(MyReport) then
    MyReport.Free;

  Didn't work. Still the same error.
  I also introduce a local variable of the report (so that it would
automatically be clean upafter the procedure exits).

procedure PrintReport;
var
  ARep: TMyReport;
begin
  if (CurrentRecord <> -1) then
  begin
    // I'd reintroduce the constructor to pass in the record number
    ARep := TMyReport.Create(Self,CurrentRecord);
    ARep.Preview;
  end;
end;

  On running the second time, it tells me "A component name MyReport is
already present", meaning it's using the variable automatically created in
TMyReport's unit.
  Anyone can help? Thanks.
________
cLiffordiL

 

Re:QR gives violation error when running for the second time


Assuming that TMyReport is  TForm descendant and you have
put the TQuikcRep in it this  could hopefully shud do the
job ....

with TMyReport.Create(self,CurrentRecord)  do
try
  Applicatiion.ProcessMessages // :-)
  QuickRep.Preview;
{ unless you have a preview method in the TMyReport class to
do something like that }
finaly
  Free;
end;

HTH
regards
angshu

Quote
"cLiffordiL" <cliffor...@singmail.com> wrote in message

news:3b0db842_1@dnews...
Quote
> Hi,
>   I'd built a report using QR3.0.5 & D5E. My report is
executed by a 2nd
> level form (meaning it is Main parent's child's child
form). I have the
> following to print my report:

> procedure PrintReport;
> begin
>   if (CurrentRecord <> -1) then
>   begin
>     MyReport.Free;
>     // I'd reintroduce the constructor to pass in the
record number
>     MyReport := TMyReport.Create(Self,CurrentRecord);
>     MyReport.Preview;
>   end;
> end;

>   The first execution proves fine. When I click on my
print button again
> (which runs the procedure), or exit out, open another

record and runs print

- Show quoted text -

Quote
> again, it gives me an access violation error.
>   Since it halted at the Free line, I thought there's a
bug there. I
> modified that line to detect whether there was a report
previously create:

>   if Assigned(MyReport) then
>     MyReport.Free;

>   Didn't work. Still the same error.
>   I also introduce a local variable of the report (so that
it would
> automatically be clean upafter the procedure exits).

> procedure PrintReport;
> var
>   ARep: TMyReport;
> begin
>   if (CurrentRecord <> -1) then
>   begin
>     // I'd reintroduce the constructor to pass in the
record number
>     ARep := TMyReport.Create(Self,CurrentRecord);
>     ARep.Preview;
>   end;
> end;

>   On running the second time, it tells me "A component
name MyReport is
> already present", meaning it's using the variable

automatically created in

- Show quoted text -

Quote
> TMyReport's unit.
>   Anyone can help? Thanks.
> ________
> cLiffordiL

Re:QR gives violation error when running for the second time


Try Yapi on yapi.webjump.com.  Its free and doesn't crash

Owen Mooney

Quote
cLiffordiL wrote:
> Hi,
>   I'd built a report using QR3.0.5 & D5E. My report is executed by a 2nd
> level form (meaning it is Main parent's child's child form). I have the
> following to print my report:

> procedure PrintReport;
> begin
>   if (CurrentRecord <> -1) then
>   begin
>     MyReport.Free;
>     // I'd reintroduce the constructor to pass in the record number
>     MyReport := TMyReport.Create(Self,CurrentRecord);
>     MyReport.Preview;
>   end;
> end;

>   The first execution proves fine. When I click on my print button again
> (which runs the procedure), or exit out, open another record and runs print
> again, it gives me an access violation error.
>   Since it halted at the Free line, I thought there's a bug there. I
> modified that line to detect whether there was a report previously create:

>   if Assigned(MyReport) then
>     MyReport.Free;

>   Didn't work. Still the same error.
>   I also introduce a local variable of the report (so that it would
> automatically be clean upafter the procedure exits).

> procedure PrintReport;
> var
>   ARep: TMyReport;
> begin
>   if (CurrentRecord <> -1) then
>   begin
>     // I'd reintroduce the constructor to pass in the record number
>     ARep := TMyReport.Create(Self,CurrentRecord);
>     ARep.Preview;
>   end;
> end;

>   On running the second time, it tells me "A component name MyReport is
> already present", meaning it's using the variable automatically created in
> TMyReport's unit.
>   Anyone can help? Thanks.
> ________
> cLiffordiL

Other Threads