unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

    var dpCrLf : AnsiString = chr(13)+chr(10);
    var szSavePath : String = 'C:\Argox';
    var szSaveFile : AnsiString = 'C:\Argox\PPLZ_Example.Prn';
    var sznop1     : AnsiString = 'nop_front' + Chr(13) + chr(10);
    var sznop2     : AnsiString = 'nop_middle' + Chr(13) + chr(10);
    function  Z_Bar2d_Maxi(x:integer; y:integer; nMode:integer; nSymbol:integer; nTotal:integer;
              nClass:integer; nCountry:integer; cZipCode1:AnsiString; cZipCode2:AnsiString; data:AnsiString;
              increase:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Bar2d_PDF417(x:integer; y:integer; o:integer; h:integer; s:integer; c:integer;
              r:integer; t:integer; narrow:integer; data:AnsiString; increase:integer):integer;stdcall;
              external 'WINPPLZ.DLL';
    function  Z_Bar2d_DataMatrix(x:integer; y:integer; o:integer; h:integer; c:integer; r:integer;
              data:AnsiString; increase:integer):integer;stdcall;external 'WINPPLZ.DLL';
    Procedure Z_ClosePrn();stdcall;external 'WINPPLZ.DLL';
    function  Z_CreatePrn(selection:integer; filename:AnsiString):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_FlashMemory(Status:integer):integer;stdcall;external 'WINPPLZ.DLL';
    Procedure Z_Set_Format_New(FormatName:AnsiString);stdcall;external 'WINPPLZ.DLL';
    function  Z_Del_Format(memory:integer; formatname:AnsiString):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Del_Graphic(memory:integer; graphicname:AnsiString):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Draw_Box(x:integer; y:integer; width:integer; height:integer; thickness:integer)
              :integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Draw_Line(x:integer; y:integer; width:integer; height:integer):integer;stdcall;
              external 'WINPPLZ.DLL';
    function  Z_Get_DLL_Version(nShowMessage:integer):PAnsiChar;stdcall;external 'WINPPLZ.DLL';
    function  Z_Get_DLL_VersionA(nShowMessage:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Get_Graphic_ColorBMP(x:integer; y:integer; mem_mode:integer; filename:AnsiString):integer;
              stdcall;external 'WINPPLZ.DLL';
    function  Z_Get_Graphic_ColorBMPEx(x:integer; y:integer; nWidth:integer; nHeight:integer;
              rotate:integer; mem_mode:integer; id_name:AnsiString; filename:AnsiString):integer;
              stdcall;external 'WINPPLZ.DLL';
    function  Z_Get_Graphic_ColorBMP_HBitmap(x:integer; y:integer; nWidth:integer; nHeight:integer;
              rotate:integer; mem_mode:integer; id_name:AnsiString; hbm:HBITMAP):integer;
              stdcall;external 'WINPPLZ.DLL';
    function  Z_Initial_Setting(Type_Renamed:integer; Source:AnsiString):integer;stdcall;
              external 'WINPPLZ.DLL';
    function  Z_WriteData(IsImmediate:integer; pbuf:AnsiString; length:integer):integer;stdcall;
              external 'WINPPLZ.DLL';
    function  Z_ReadData(pbuf:PAnsiChar; length:integer; dwTimeoutms:integer):integer;stdcall;
              external 'WINPPLZ.DLL';
    function  Z_Load_Graphic(x:integer; y:integer; memory:integer; graphic_name:AnsiString;
              horizontal:integer; vertical:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Open_ChineseFont(path:AnsiString):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Print_Form(copies:integer; labset:integer; mem_mode:integer; form_out:AnsiString):integer;
              stdcall;external 'WINPPLZ.DLL';
    function  Z_Print_Out(sets:integer; copies:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Prn_Barcode(x:integer; y:integer; ori:integer; narrow:integer; width:integer;
              height:integer; type_Renamed:char; increase:integer; data:AnsiString; human1:char;
              human2:char; human3:char; human4:char; human5:char):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Prn_Text(x:integer; y:integer; ori:integer; font:char; height:integer; width:integer;
              numeric:integer; data:AnsiString):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Prn_Text_Chinese(x:integer; y:integer; fonttype:integer; id_name:AnsiString; data:AnsiString;
              mem_mode:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Prn_Text_TrueType(x:integer; y:integer; FSize:integer; FType:AnsiString; Fspin:integer;
              FWeight:integer; FItalic:integer; FUnline:integer; FStrikeOut:integer; id_name:AnsiString;
              data:AnsiString; mem_mode:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Prn_Text_TrueType_W(x:integer; y:integer; FHeight:integer; FWidth:integer; FType:AnsiString;
              Fspin:integer; FWeight:integer; FItalic:integer; FUnline:integer; FStrikeOut:integer;
              id_name:AnsiString; data:AnsiString; mem_mode:integer):integer;stdcall;external 'WINPPLZ.DLL';
    Procedure Z_Clear_Memory();stdcall;external 'WINPPLZ.DLL';
    Procedure Z_Clear_MemoryEx(nMode:integer);stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Backfeed(nDistance:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Darkness(darkness:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_DebugDialog(nEnable:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Label(Length:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Mode(mode:char):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Origin(y:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Paper(mode:char):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Prncomport(baud:integer; parity:integer; data:integer; stop:integer):integer;
              stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Prncomport_PC(nBaudRate:integer; nByteSize:integer; nParity:integer;
              nStopBits:integer; nDsr:integer; nCts:integer; nXonXoff:integer):integer;stdcall;
              external 'WINPPLZ.DLL';
    Procedure Z_Set_Reset();stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Speed(print:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_TPH(mode:char):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Unit(Unit_Rename:char):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_Gap(nPatern:integer; nGap:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_ProcessDlg(nShow:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_ErrorDlg(nShow:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Bar2d_QRCode(x:integer; y:integer; nModel:integer; nMagni:integer; nErr_Cor:integer;
              nInput:integer; data:AnsiString; increase:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_PrintWidth(nDotwidth:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Print_OutQuality(nTotal:integer; sets:integer; copies:integer; nPause:integer)
              :integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_GetUSBBufferLen():integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_EnumUSB(buf:PAnsiChar):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_CreateUSBPort(nPort:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_CreatePort(nPortType:integer; nPort:integer; filename:AnsiString):integer;stdcall;
              external 'WINPPLZ.DLL';
    function  Z_Set_Mirror(direction:char):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Bar2d_RSS(x:integer; y:integer; ori:char; rtype:integer; mag:integer; height:integer;
              seg:integer; data1:AnsiString; data2:AnsiString):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_GetNetPrinterBufferLen():integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_EnumNetPrinter(buf:PAnsiChar):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_CreateNetPort(nPort:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Prn_Text_TrueType_Uni(x:integer; y:integer; FSize:integer; FType:AnsiString; Fspin:integer;
              FWeight:integer; FItalic:integer; FUnline:integer; FStrikeOut:integer; id_name:AnsiString;
              data:PWideChar; format:integer; mem_mode:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Prn_Text_TrueType_UniB(x:integer; y:integer; FSize:integer; FType:AnsiString; Fspin:integer;
              FWeight:integer; FItalic:integer; FUnline:integer; FStrikeOut:integer; id_name:AnsiString;
              data:PWideChar; format:integer; mem_mode:integer):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_GetUSBDeviceInfo(nPort:integer; pDeviceName:PAnsiChar; pDeviceNameLen:PInteger;
              pDevicePath:PAnsiChar; pDevicePathLen:PInteger):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Set_EncryptionKey(encryptionKey:AnsiString):integer;stdcall;external 'WINPPLZ.DLL';
    function  Z_Check_EncryptionKey(decodeKey:AnsiString; encryptionKey:AnsiString;
              dwTimeoutms:integer):integer;stdcall;external 'WINPPLZ.DLL';

procedure TForm1.Button1Click(Sender: TObject);
var
     ret,nLen,sw : integer;
     pbuf : array[0..127] of AnsiChar;
     ver : PAnsiChar;
     strmsg : string;
     len1,len2 : integer;
     buf1,buf2 : AnsiString;
     buff1 : array[0..127] of WideChar;
     himage : HBITMAP;
begin
     // Test code start
     // open port.
     // dll version.
     ver := Z_Get_DLL_Version(0);
     
     // search port.
     nLen := Z_GetUSBBufferLen() + 1;
     strmsg := 'DLL ' + ver + dpCrLf;   // only sample coding, not smart.
     If nLen > 1 then
     begin
         len1 := 128;
         len2 := 128;
         SetLength(buf1,len1);
         SetLength(buf2,len2);
         Z_EnumUSB(pbuf);
         Z_GetUSBDeviceInfo(1, PAnsiChar(buf1), @len1, PAnsiChar(buf2), @len2);
         sw := 1;
         If 0 < sw then
                ret := Z_CreatePrn(12, PAnsiChar(buf2)) // open usb.
         else
                ret := Z_CreateUSBPort(1); // must call Z_GetUSBBufferLen() function fisrt.
         If 0 < ret then
             strmsg := strmsg + 'Open USB fail!'
         else
         begin
             SetLength(buf1,len1);
             SetLength(buf2,len2);
             strmsg := strmsg + 'Open USB:' + dpCrLf + 'Device name: ';
             strmsg := strmsg + buf1;
             strmsg := strmsg + dpCrLf + 'Device path: ';
             strmsg := strmsg + buf2;
             //sw := 2;
             If 2 = sw then
             begin
                //get host status.
                Z_WriteData(1, '~HS'+chr(13)+chr(10), 5);   //~HS
                ret := Z_ReadData(pbuf, 82, 1000);
             end;
         end;
     end
     else
     begin
         CreateDirectory(PChar(szSavePath), nil);
         ret := Z_CreatePrn(0, szSaveFile);   // open file.
         strmsg := strmsg + 'Open ' + szSaveFile;
         if 0 < ret then
             strmsg := strmsg + ' file fail!'
         else
             strmsg := strmsg + ' file succeed!';
     end;
     ShowMessage(strmsg);
     If 0 < ret then
         exit;
     
     // sample setting.
     Z_Set_DebugDialog(1);
     Z_Set_Origin(0);
     Z_Set_Paper('Y');
     Z_Set_TPH('D');
     Z_Set_Unit('D');   // dot.
     Z_Set_Darkness(8);
     Z_Set_Label(203 * 3);
     Z_Set_PrintWidth(203 * 4);
     Z_Clear_Memory();   // clear memory.
     Z_WriteData(0, sznop2, StrLen(PAnsiChar(sznop2)));
     Z_WriteData(1, sznop1, StrLen(PAnsiChar(sznop1)));

     // draw box.
     Z_Draw_Box(20, 20, 760, 560, 4);
     Z_Draw_Line(400, 20, 4, 560);

     // print text, true type text.
     Z_Prn_Text(30, 40, 1, 'D', 1, 1, 0, 'PPLZ Lib Example');
     Z_Prn_Text_TrueType(30, 100, 30, 'Arial', 1, 400, 0, 0, 0, 'AA', 'TrueType Font', 0);   // save in printer.
     Z_Prn_Text_TrueType_W(30, 160, 20, 20, 'Times New Roman', 1, 400, 0, 0, 0, 'AB', 'TT_W: 多字元測試', 0);

     StringToWideChar('TT_Uni: 多字元測試', buff1, 128);  // Converts double-byte characters to UNICODE(wide characters).
     buff1[13] := #$0000;   // null.
     Z_Prn_Text_TrueType_Uni(30, 220, 30, 'Times New Roman', 1, 400, 0, 0, 0, 'AC', buff1, 1, 0);   // UTF-16

     buff1[0] := #$FEFF;   // UTF-16.
     StringToWideChar('TT_UniB: 多字元測試', buff1+1, 128);  // Converts double-byte characters to UNICODE(wide characters).
     buff1[15] := #$0000;   // null.
     Z_Prn_Text_TrueType_UniB(30, 280, 30, 'Times New Roman', 1, 400, 0, 0, 0, 'AD', buff1, 0, 0);   // Byte Order Mark.

     // barcode.
     Z_Prn_Barcode(420, 100, 1, 2, 3, 40, '3', 1, '1234', 'N', 'Y', 'N', 'N', 'N');   // have a counter.
     Z_Bar2d_QRCode(420, 190, 2, 3, 3, 1, 'QR CODE', 0);

     // picture.
     Z_Get_Graphic_ColorBMP(420, 280, 0, 'bb.bmp');// Color bmp file to ram.
     Z_Get_Graphic_ColorBMPEx(420, 330, 200, 150, 2, 0, 'bb1', 'bb.bmp');//180 angle
     himage := LoadImage(0, 'bb.bmp', IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
     Z_Get_Graphic_ColorBMP_HBitmap(630, 280, 250, 80, 1, 0, 'bb2', himage);//90 angle.
     If 0 <> himage then
         DeleteObject(himage);
         
     // output.
     Z_Print_Out(2, 1);   // copy 2.
     
     // close port.
     Z_ClosePrn();
end;

end.
