自己动手丰衣足食,自己做一个怎么样?条码打印也是Canvas画的,画条码只要知道条码的生成规则就可以了。
比如39码的方法:在這篇文章中我們並不會去探討各種條碼的規格及特性,有關各種條碼的說明請各位讀者自行查閱相關書籍,在這裡我們僅以39碼為例來說明條碼元件的撰寫。首先我們來看看39碼的特性:1. 39碼包含5條黑線及4條白線
2. 39碼以黑線為起始,黑線為結束,黑白相間
3. 39碼的線條共分4種:粗黑線、粗白線、細黑線、細白線
4. 39碼可表示的資料為 ”0”~”9”,”A”~”Z”,”+”,”-“,”*”,”/”,”%”,”$”,”.”,空白字元,總共43個字元。字元的對應值如下:
0: 0  1:1  2:2  3:3  4:4  5:5  6:6  7:7  8:8  9:9  A:10  B:11  C:12  D:13  E:14  F:15  G:16  H:17  I:18  J:19  K:20  L:21  M:22  N:23  O:24  P:25  Q:26  R:27  S:28  T:29  U:30  V:31  W:32  X:33  Y:34  Z:35  -:36  .:37  空白:38  $:39  /:40  +:41  %:42
5. 39碼以”*”為起始碼及結束碼
6. 39碼可在資料之後加一個檢查碼,檢查碼可有可無,檢查碼的公式如下:
CheckSum = Sum(資料字元的對應值) mod 43
生成一个TComponent的继承类;
    TCarCode = Class(TComponent)
      FImage : TImage;
      FCode  : string
      procedure SetCode(Value : string);
      procedure DrawBarcode(newValue : string);
    published
      property Image : TImage read FImage write FImage;
      property Code : string read FCode write SetCode;
    end; procedure TCarCode.SetCode(Value : string);
begin
  FCode := Value;
  DrawBarcode(FCode);
end;
procedure TCarCode.DrawBarcode(newValue : string);
var
  i,pos : integer;        
  checkSum  : Long       ;
  oldValue : string;
  CheckSumFlag,notFound : Boolean;
begin
    // Add CheckSum
    if CheckSumFlag then 
    begin
        int checkSum = 0;
        newValue := Trim(oldValue);        for i := 1 to  Length(newValue)+1 do  
        begin
            pos := 0;
            notFound := true;
            while (pos < 43) and notFound 
            begin
                if(code39[pos][0] = FnewValue[i] then 
                begin
                    checkSum := checkSum+pos;
                    notFound := false;
                end;                Inc(pos);
            end;
        end;        checkSum = checkSum % 43;
        newValue = oldValue + code39[checkSum][0];
    end else begin
        newValue = oldValue;
    end;
end;
其中code39是一个二维的数组,其第一维存放Ascii码的值,
第二维存放的是Ascii码对应的Code的值.应该明白了吧!
 

解决方案 »

  1.   

    www.inprises.com上有现成的控件,看看源码就行了。
      

  2.   

    我有一個sample, 是否要mail給你
    [email protected]
      

  3.   

    谢谢几位高人!
    昨天公司维修停电,没能及时赶到csdn,向各位大虾请教
    谢谢Brand1(孤独的人),
    if(code39[pos][0] = FnewValue[i] then 
    这一句没看懂,FnewValue是什么?
     
      

  4.   

    谢谢zhanggy(阿光),我下载了,正在看!
      

  5.   

    jyc_lin(lianglin):
    有没有原码 
      

  6.   

    freddyzhu :
    能在专用打印机上实现,已在一家鞋廠實際使用, 請把mail告我
    liang lin
    2001.09.21