How to use a crystal report in Delphi

xiaoxiao2021-03-06  20

1, Project - Import Type Library A box

2, select Crystal Report X Activex Designer Runtime Library in Box (x What is the version of your crystal report, such as 8.5, that x is 8.5) 3. Click Install to press New, then click INTO New Package (here you will ask you Enter a path (such as: e: /borland/delphi6/lib/cradrl.dpk), click OK. You can add an Application object in the Delphi's ActiveX in the determination box.

4. Drag and drop the Application to Form1, and Project automatically generates the following code: Unit unit1;

Interface

Useswindows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs

Typetform1 = Class (TFORM) Application1: Tapplication; Procedure formcreate (sender: TOBJECT); private {private declarations} end;

Varform1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TFORM1.FormCreate (Sender: TOBJECT); Begin

END;

End.

After adding APLIN, we have to add a report browsing component Crystal Reports Viewer Control (CRVIEWER.DLL) step is the same: first choose 1, Project - import type library A box

2, select Crystal Reports Viewer Control3 in Box. Click Install to press New, then click INTO New Package (here you will ask you to enter a path (such as: e: /borland/delphi6/lib/crviewer.dpk), click OK Click Yes in the determination box, add a CRVIEWER object in the ActiveX of Delphi. 4. Add it to the FORM15. Add a button in Form1 to write the following code in the Button's Click event:

Procedure TForm1.Button1Click (Sender: TOBJECT); varReport: Ireport; begin / we can open a generated report, this is dynamic, can connect to the database when the report is created, of course, can also be called in Delphi LogonServer / setLogonInfo is dynamically connected to the database. report: = Application1.OpenReport ( 'c: /report1.rpt',crOpenReportByTempCopy); / * The CrOpenReportByDefault constant places a lock on the RPT file preventing it from being accessed by other applications or users CrOpenReportByTempCopy is often preferred since it opens a. Temporary Copy of The Rpt File INSTEAD. * /

转载请注明原文地址:https://www.9cbs.com/read-43687.html

New Post(0)