Delphi 调用Codesoft打印条码

来源:互联网 发布:蕾丝布料淘宝 编辑:程序博客网 时间:2024/06/11 17:14

使用Delphi调用CodeSoft打印条码,使用OLE控件的方法。但需要注意的Codesoft是正式的安装版,使用绿色版不行,绿色版没有写注册表。

下面是测试通过的列子:(需要引用ComObj.Pas文件)

function DoPrint:Boolean;
var
  barApp: Variant;
  BarDoc,BarVars: Variant;
  vPath: string;
begin
  Result := False;
  try
    vPath := ExtractFilePath(Forms.Application.ExeName);
    // 打印第一页
    if not FileExists(vPath+'TEST.Lab') then
    begin
      showMessage('打印标签不存在,请检查!');
      Exit;
    end;

    BarApp := CreateOleObject('lppx.Application');
    BarApp.Visible:=False;
    BarDoc:=BarApp.ActiveDocument;
    BarVars:=BarDoc.Variables;
    BarDoc.Open(vDSNFile);

    // 'TEXT'、'BARCODE'均为TEST.Lab标签纸上的控件名称
    BarDoc.Variables.Item('TEXT').Value := 'TEXTValue';  
    BarDoc.Variables.Item('BARCODE').Value := 'BARCODEValue'; 
    Bardoc.Printlabel(1);   // 其中1是打印份数,你想打印几份,设置成几就可以了
    BarDoc.FormFeed;
    Bardoc.Close;

    BarApp.Quit;

  except
    on E: Exception do
    begin
      ShowMessage(E.ClassName + E.Message);
      Exit;
    end;
  end;
  Result := True;
end;

Delphi调用Bartender也是一样的道理。参见 http://blog.csdn.net/qq_19784269/article/details/50570177


0 0