使用Delphi調用條形碼控件BarTender打印標簽


1. 要實現的條形碼功能
最近一個項目需要在掃描條碼后按固定的格式打印。 條形碼打印控件客戶習慣使用的是BarTender,使用Delphi調用BarTender來完成打印條碼標簽功能。此功能的重點在於:
a)         使用BarTender格式打印
b)        格式中有需要變動的部分
2.  條形碼標簽設計
a)       新建一個空白標簽
b)      在畫面上加入一個條形碼控件,一個文本控件
c)       選中 條形碼控件,雙擊(或右鍵,屬性),打開屬性窗口;點擊“高級”,選擇“共享/名稱”頁,在共享名稱中輸入條形碼控件的名字“BarCode1”;點擊確定完成修改。這個步驟來定義在Delphi中(或其它語言VB等)訪問的對象名。
d)      同樣的步驟,給文本控件設置名稱為“Text1”
e)       保存為“c:/test.btw”
3.  導入ActiveX組件
a)         打開Delphi(版本5.0及以上,其它沒有測試)
b)        選擇菜單“項目”à“導入類型庫”(ProjectàImport Type Library)
c)         在彈出的窗口中,列出可導入的類型庫;找到“BarTender 7.75”,選中
d)        將要導入的類名稱會列在class names中,由於這里的類名稱會與系統已存在類名稱有重復,將這個全部復制出來,將類型名稱前面都加上Bt。如:TFormat修改為TBtFormat.
e)         類名稱修改完成后,點擊”安裝”(Install)
f)         系統會安裝組件到ActiveX控件頁上
4. 調用BarTender打印
a)         新建應用程序
b)        在窗體上拖一個TBtApplication控件(ActiveX頁上),命名為btApp1
c)         在窗體上放一個TButton控件,命名為btn1,雙擊btn1產生事件
d)        填寫事件代碼如下:
procedure TForm1.btn1Click(Sender: TObject);
begin
 with btApp1.Formats.Open('c:/test.btw', True, '') do //打開標簽文件
 begin
    SetNamedSubStringValue('BarCode1', '1234567890'); //設置值
    SetNamedSubStringValue('Text1', 'Hello BarTender!');
    PrintOut(False, False); //打印
    Close(btDoNotSaveChanges); //關閉不保存
 end;
 btApp1.Quit(btDoNotSaveChanges); //退出
end;
 

 

 
0
------


The Formats.Open method has three arguments. The first argument is required and is a string containing the path of the label format file to open. The second argument is a Boolean: if it is true, the method will close the default blank format called "Format1" that BarTender automatically opens when it starts. It cannot close formats that have any other name. The third argument specifies a printer to use.

If you have multiple formats opened in BarTender, you can use the Formats collection object to return a reference to any opened format. A format can be identified by specifying either the format name or index identifier. You can also bring focus to an opened label format using the Format.Activate method. The following example assigns the specified label format (Format1.btw) to be the active label format in BarTender.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM