Draws a barcode symbol on the specified canvas. There are several different overloading methods, Syntax 1, Syntax 2, and Syntax 3 (only for Delphi/C++Builder 2009 or later):
For the TBarcode1D_Code128 and the TBarcode1D_EAN128 components, if you use them in the Delphi/C++ Builder 2007 or early, the Barcode parameter is in fact an AnsiSting in ANSI encoding scheme. If you want to use other encoding scheme (for example the UTF-8, UTF-16), please convert it in the OnEncode event, or specify the converted string in the Barcode paramater. Also, you can use the method to encode a block of binary (bytes) data; If you use them in the Delphi/C++ Builder 2009 or later, it is in fact an UnicodeString instead of AnsiString. By default, the unicode string will be converted to an ANSI encoding string, then be encoded into the barcode symbol. If you want to use other encoding scheme (for example the UTF-8, UTF-16), please convert it in the OnEncode event, or use the DrawTo (Syntax 3) overloading method and specify the converted string in its Data paramater. If you want to encode block of binary (bytes) data, please use the DrawTo (Syntax 3) overloading method.
For the TBarcode1D_Code128 and the TBarcode1D_EAN128 components, you can use the method to encode a block of binary (bytes) data under Delphi/C++ Builder 2009 or later. If you want to encode a block of binary (bytes) data into a barcode symbol under Delphi/C++ Builder 2007 or early, please use the DrawTo (Syntax 2) overloading method.
For Delphi 3, the method overload isn't supported, so the method names of Syntax 1 and Syntax 2 are changed to DrawTo1 and DrawTo2.
The method uses GetDeviceCaps function to retrieves device-specific information for the specified device. When using Printer.Canvas as the target cvanvas, it will fail if a default printer is not set in Windows. Please ensure that a default printer is specified in Windows:
Set default printer for current application:
uses Winapi.Printers;
procedure SetAppPrinter(const PrinterName: string);
var
Idx: Integer;
begin
Idx := Printer.Printers.IndexOf(PrinterName);
if Idx <> -1 then
Printer.PrinterIndex := Idx
else
ShowMessage('Printer not found!');
end;
Set the global default printer.
uses Winapi.WinSpool;
procedure SetWindowsDefaultPrinter(const PrinterName: string);
begin
if SetDefaultPrinter(PChar(PrinterName)) then
SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0)
else
RaiseLastOSError;
end;