玄铁剑

成功的途径:抄,创造,研究,发明...
posts - 128, comments - 42, trackbacks - 0, articles - 174

Bartender 多线程同步打印条码

Posted on 2007-09-10 21:13 玄铁剑 阅读(1675) 评论(2)  编辑 收藏 引用 所属分类: delphi

{*
//多线程同步打印条码
procedure TLotBarCodePrintForm.btnPrintClick(Sender: TObject);
var
  thLotPrint: TthLotPrint;
begin
  if hMutex = 0 then
    hMutex := CreateMutex(nil, False, nil);
  thLotPrint := TthLotPrint.Create(StrLot, StrSize, intFront, intBefore,cbSubLot.Checked);
  thLotPrint.Resume;
end;
*}


unit thLotPrint;

interface

uses
  Windows, Dialogs, Classes, Forms, SysUtils, Variants, clsCommFunction, clsDtSet, clsGlobal, ComObj, StrUtils, Math,
  ComCtrls, StdCtrls, ExtCtrls;

type
  TthLotPrint = class(TThread)
  private
    StrLotID: string;
    StrSize: string;
    iMinValue, iMaxValue: Integer;
    bPrintSub:Boolean;
    btApp: Variant;
    btFormat: Variant;
    function GetSizeDesc(StrLot, StrSize: string): string;
    function GetLeftQty(iTimes: Integer; StrLotID, StrSize: string): Integer;
    function GetRightQty(iTimes: Integer; StrLotID, StrSize: string): Integer;
    function GetSizeQtyStr(iTimes, iLeft, iRight: Integer): string;
  protected
    procedure Execute; override;
  public
    constructor Create(InStrLot, InStrSize: string; intMin, intMax: Integer;isPrintSub:Boolean);
  end;

var
  hMutex: THandle = 0;

implementation

uses LotBarcodePrintFrm;

constructor TthLotPrint.Create(InStrLot, InStrSize: string; intMin, intMax: Integer;isPrintSub:Boolean);
begin
  StrLotID := InStrLot;
  StrSize := InStrSize;
  iMinValue := intMin;
  iMaxValue := intMax;
  bPrintSub:=isPrintSub;
  inherited create(False);
end;

procedure TthLotPrint.Execute;
begin
  FreeOnTerminate := True;

  if WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 then
  begin

  //Open bartender connection
    btApp := CreateOleObject('Bartender.application');
    btApp.Visible := False;

  //Open bartender format file
    btFormat := btApp.Formats.Open(ExtractFilePath(Application.ExeName) + 'Lab\barcode.btw', true, '')


    //Print barcode use bartender

    //AA表示标签格式文件中接收的叁数名称
      btFormat.SetNamedSubStringValue('AA', rsComkey);
 

      btFormat.PrintOut(0, 0);

      if bStopThreadDo then
        Break;
    end;

    //Close bartender connection
    btApp.Quit(1);
    btApp := Null;
  end;
  ReleaseMutex(hMutex);
end;


end.

 

Feedback

# re: Bartender 多线程同步打印条码  回复  更多评论   

2008-06-05 10:44 by 沉沉
请问:我程序运行到CreateOleObject('Bartender.application')就报错,提示‘无效的类别字符串’,是我需要注册什么吗?Bartender已经安装了。
还有clsCommFunction, clsDtSet, clsGlobal是您自定义的吗?起什么作用。
谢谢。

# re: Bartender 多线程同步打印条码  回复  更多评论   

2008-06-05 21:32 by 玄铁剑
clsCommFunction, clsDtSet, clsGlobal是自定义的,安装了Bartender就可以了。这是前几年做Delphi的时候弄的。
只有注册用户登录后才能发表评论。