Loading and Displaying an Image (Delphi 4.0)

Take the following steps to start a project and to add some code that positions, scales, and displays an image on the main form:

1. Start Delphi 4.0.

2. On the Delphi toolbar, click the ActiveX tab, if one is present. If you have not added any ActiveX controls, there will not be an ActiveX tab present. If you have used a LEAD ActiveX control before, the icon appears on the toolbar. If no ActiveX controls are present, or if this control is not present, add the LEAD control as follows:

a. On the Component menu, choose Import ActiveX Control.

b. In the Import ActiveX dialog box, highlight the LEAD Main Control (12). Change the Class name to TLEAD. Click the Install button.

c. In the Install dialog, click OK.

d. In the Confirm dialog, click Yes. You will also see the Compiling package dclusr40 dialog confirming that dclusr40 will be compiled. Click Yes.

e. After compilation has finished, click OK in the Information dialog.

f. At this point you will be presented with the dclusr40.pas window, with a Contains folder. Within this folder are LEAD .dcr and .pas files. Save the dclusr40 project.

3. In the File menu, choose New Application.

4. Select the LEAD control on the ActiveX toolbar. Size and position the control as you want it to appear at run time, and change the name of the control to LEAD1.

5. Add a command button to your form and name it as follows:

Name

Caption

LoadLead

Load Image

6. In the Project menu, choose Add to Project, and add the LEADDEF.PAS file from LEAD's \INCLUDE directory.

7. Select the Unit1 tab in the editor window. On the File menu, select Use Unit. Highlight LEADDEF and select OK.

8. Code the main form's FormShow procedure as follows. In online help, you can copy the block of code and paste it into your application.

procedure TForm1.FormShow(Sender: TObject);
begin

  { Set defaults for displaying the image. }
  { These are all persistent properties that can be set in the properties box. }
  Lead1.Appearance := APPEARANCE_FLAT;
  Lead1.BorderStyle := 1;
  Lead1.BackColor := RGB(255, 255, 125);
  Lead1.PaintDither := PAINTDITHER_DIFFUSION;
  Lead1.PaintPalette := PAINTPALETTE_AUTO;
  Lead1.AutoRepaint := True;
  Lead1.AutoSize := False;
  Lead1.AutoSetRects := True;
  Lead1.PaintSizeMode := PAINTSIZEMODE_FIT;

end;

9. Code the LoadLead button's click procedure as follows:

procedure TForm1.LeadLoadClick(Sender: TObject);
begin
    Lead1.Load('c:\lead\images\image1.cmp', 0, 0, 1);
end;

10. Run your program to test it.

11. Save the project to use as a starting point for other tasks in this tutorial.