Soal CPNS, Lowongan CPNS, Lowongan Kerja

Monday, July 21, 2008

use barcodes in Delphi (4-7)

You can use ActiveBarcode in Delphi like any other control (e.g. like a button). First you have to add the ActiveBarcode control into the Delphi development environment.

Add ActiveBarcode to the Delphi development environment
(The is also a description for older Delphi versions (4-7) available)

Select a package in which you would like to take up the Control or create a new package ("File" - "New" - "Package Delphi for Win32 "):

Save this package under an own name with the "Save as" function. For example as "ActiveBarcodePackage".

Now import the ActiveBarcode Control in the package. Launch the function "Component import" from the menu "Component".

The "Component dialog" appears:

Select "ActiveX control" and click "Continue". Now a list of the available contols will be shown:


Select "ActiveBarcode" from that list and click "Continue". A page for compontent setup will be shown:

You don't need to change something here. Click "Continue". A page for "Install" appears.

Select "Add unit to the project .." here and click on "Finish". Now ActiveBarcode is added as a component to the package. Now you must compile the package. Select the function " ActiveBarcodePackage create" from the menu "Project":



Use ActiveBarcode (Example)

Create a new project: "File" - "New" - "Form application VCL". To place ActiveBarcode now onto a form you select the ActiveBarcodeControl from the tool palette. You'll find this under "ActiveX" as a "TBarcode" component:

Select TBarcode and place the component on the form. In the object inspector you can customize the properties of the component. E.g. set the background color on white.


For this example add one more TEdit to the form. Now you form might look as follows:

Now we "link" the edit field directly with the control. Open the source code for the "textchange" event by double clicking the edit field. This event always is called, if the contents of the edit field are changed. Ideally for our example. We give this update immediately to the control.

That's it. Now launch the program:


Change the content of the edit field to change the barcode.

Programming:
Setting properties is very simple. Some examples:

Barcode1.Text := '123456789012';
Barcode1.BackColor := clWhite;
Barcode1.ForeColor := clBlack;
Using the Picture Property:
Copy the barcode to a image object:
Image1.Picture.Bitmap.Height := Barcode1.Height;
Image1.Picture.Bitmap.Width := Barcode1.Width;
Barcode1.Picture.PictureAdapter := nil; // delphi workaround
Image1.Picture.Bitmap.Canvas.Draw(0,0,Barcode1.Picture.graphic);
Clipboard:
Copy the current barcode to the clipboard. Metafile (WMF):
  Barcode1.CopyToClipboard;
Bitmap:
Image1.Picture.Bitmap.Height := Barcode1.Height;
Image1.Picture.Bitmap.Width := Barcode1.Width;
Barcode1.Picture.PictureAdapter := nil; // delphi workaround
Image1.Picture.Bitmap.Canvas.Draw(0,0,Barcode1.Picture.graphic);
Clipboard.Assign(Image1.Picture.Bitmap);

No comments: