使用LabelView软件的COM服务来对LabelView进行控制,即传递数据到LabelView的条码对象上,使我们可以自定义需要打印的条码数据。
首先,导入类型库。在[Import Type Library]中选择LabelView Ole Automation server TypeLib V6.0创建单元即可。 生成单元LabelView_TLB.pas,单元中包含了很多的接口,ILabelApplication,ILabelDocument,ILabelField,ILabelFields,IlabelPrinter,通过这些接口就可以进行进程间的通信了,也就可以控制LabelView文件中的对象的操作了。
研究了半天,还是要认真学习一下COM了。
以下是对3.lbl文件中的条形码进行赋值代码。
uses
LabelView_TLB;
var
Form1: TForm1;
LabelApp: ILabelApplication;
LabelDoc: ILabelDocument;
LabelFields: ILabelFields;
LabelField: ILabelField;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
iDIsp: IDispatch;
begin
//应用程序接口实现
LabelApp := CoLabelApplication.Create;
LabelApp.Visible := True;
iDIsp := LabelApp.ActiveDocument;
if iDIsp <> nil then
begin
//获取文档接口
iDIsp.QueryInterface(ILabelDocument, LabelDoc);
LabelDoc.Open('3.lbl', false); //打开文件
iDIsp := LabelDoc.LabelFields; //获取字段列表接口
if iDIsp <> nil then
iDIsp.QueryInterface(DIID_ILabelFields, LabelFields);
iDIsp := LabelFields.Item('BARCODE1');
if iDIsp <> nil then
iDIsp.QueryInterface(DIID_ILabelField, LabelField); //获取字段接口
LabelField.Value := '123'; //通过接口进行设置
//LabelDoc.LabelSetup; //打印设置
//打印条码,数量
//LabelDoc.PrintLabel(1, 0, 0, 0, 0, 0, 0); //打印,数量为1
end;
end;
LabelView_TLB;
var
Form1: TForm1;
LabelApp: ILabelApplication;
LabelDoc: ILabelDocument;
LabelFields: ILabelFields;
LabelField: ILabelField;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
iDIsp: IDispatch;
begin
//应用程序接口实现
LabelApp := CoLabelApplication.Create;
LabelApp.Visible := True;
iDIsp := LabelApp.ActiveDocument;
if iDIsp <> nil then
begin
//获取文档接口
iDIsp.QueryInterface(ILabelDocument, LabelDoc);
LabelDoc.Open('3.lbl', false); //打开文件
iDIsp := LabelDoc.LabelFields; //获取字段列表接口
if iDIsp <> nil then
iDIsp.QueryInterface(DIID_ILabelFields, LabelFields);
iDIsp := LabelFields.Item('BARCODE1');
if iDIsp <> nil then
iDIsp.QueryInterface(DIID_ILabelField, LabelField); //获取字段接口
LabelField.Value := '123'; //通过接口进行设置
//LabelDoc.LabelSetup; //打印设置
//打印条码,数量
//LabelDoc.PrintLabel(1, 0, 0, 0, 0, 0, 0); //打印,数量为1
end;
end;