What’s wrong with this Delphi code?

Asked

Viewed 297 times

2

On the mainform onCreate, I have the following code:

procedure TForm1.FormCreate(Sender: TObject);
begin
 QuickRep1.Prepare;
 QuickRep1.Printer.Load('arquivo.qrp');
 QuickRep1.ExportToFilter(TQRAsciiExportFilter.Create('teste.txt'));
 QuickRep1.Free;
end;

It should open a QRP file and save as TXT. It even creates the test.txt, but the file is empty, with 0kb. Where I am missing?

  • 1

    To be sure I would need to download the component, but I have a doubt. The file 'file.qrp' is along with the application executable ? Tries to specify its path. Ex: 'c:/.qrp file'.

  • Yes, it is together. When I give a Quickrep1.Printer.Preview; the file is displayed, signal that it is being loaded properly

  • Can you tell me which version of Quickreport is using ?

  • is version 5.02

  • I couldn’t assemble the code as your example. In the QuickRep1.Printer.Load('arquivo.qrp'); have to trade for QuickRep1.QRPrinter.Load('arquivo.qrp'); In addition, it can provide an extension file . qrp for testing ?

1 answer

2


Try it this way:

Create 2 new variables (in the use declare interface: QRPrntr):

  vFilterLibrary : TQRExportFilterLibraryEntry;
  vExportFilter  : TQRExportFilter;     

After Prepare:

  vFilterLibrary := QRExportFilterLibrary.GetFilterByExtension('txt');
  vExportFilter  := vFilterLibrary.ExportFilterClass.Create(vNomeAnexo);
  QuickRep1.ExportToFilter(vExportFilter);

What we’re doing is locating the Filter by extension, then we ask him to create the file (correct form).

Note: For this procedure to work, the report form that will be exported must have a Filter that exports with the txt extension!

  • Compiled, but at execution gave the following error: raised exception class EAccessViolation with message 'Access violation at address 0050CBD8 in Module 'Project1.exe'. 'Read of address 000000004'. In the following line: vExportFilter := vFilterLibrary.ExportFilterClass.Create('teste.txt');

  • A breach in this line can only occur if there is no filter for the mentioned extension in the form!

  • I tested here, I put all qreport Filters in the form, tried with another format, but still gives violation :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.