{*
//多线程同步打印条码
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.