uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons, DBCtrls, DB, ADODB,
  OleCtrls, MSCommLib_TLB,activex,comobj,Tlhelp32,StrUtils,AdoConEd,Registry,
  IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient,
  IdTCPConnection, IdTCPClient, IdCmdTCPClient;
var  Form1: TForm1;
  BarApp,BarDoc,BarVars,Barcode,Texts:Variant;procedure TForm1.init();
begin
  RadioButton1.Checked:=true;
  BitBtn4.Enabled:=false;
  BitBtn2.Enabled:=false;
  Edit1.Enabled:=false;
 // Edit5.Enabled:=false;
 // Edit4.Enabled:=false;
 // Edit3.Enabled:=false;
 // Edit2.Enabled:=false;
  Edit6.Enabled:=false;
  Edit7.Enabled:=false;
  Edit8.Enabled:=false;
  Edit9.Enabled:=false;
  //setMSComm;
 if KillTask('lppa.exe')>=0 then
 begin
    try
     BarApp := CreateOleObject('lppx.Application');
    except
      Application.MessageBox('请先安装打印软件CodeSoft!','打印软件安装提示',mb_ok);
    end;
 end;end;Function TForm1.printCode(str1:String;str2:String;str3:String;str4:String):Boolean; //打印
begin
  if(str1='') or (str2='') or(str3='') or (str4='') or(Edit1.Text='') then
  begin
    application.MessageBox('打印模板或打印内容不能为空!','打印提示',mb_ok);
  end
  else
  begin
  result:=false;
  BarApp.Visible:=false;
  BarDoc:=BarApp.ActiveDocument;
  BarVars:=BarDoc.Variables;
  BarDoc.Open(Edit1.Text);
  BarDoc.Variables.Item('txt1').Value:=str1;
  BarDoc.Variables.Item('txt2').Value:=str2;
  BarDoc.Variables.Item('txt3').Value:=str3;
  BarDoc.Variables.Item('txt4').Value:=str4;
  BarDoc.Printlabel(1);
  BarDoc.FormFeed;
  BarDoc.Close;
  BarApp.Quit;
  result:=true;
end;
end;