自己动手丰衣足食,自己做一个怎么样?条码打印也是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的值.应该明白了吧!
比如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的值.应该明白了吧!
解决方案 »
- delphi 读取其它应用程序中Spreadsheet控件中的全部数据
- 有关线程的问题
- 如何用命令控制xlgrid中增加一行或一列
- 公式分析,救急!!
- 新手问题-插入记录!
- 100分相求,程序员如何找到女朋友
- 请问:我如何设置FORM的属性,可以禁止窗体的标题栏的“大小”选项?
- 问一个简单的问题!用C++BUILDER写的控件能在delphi上用吗?
- 如何用BDE连接ACCESS. 问了若干次没人给我一个完整的答案。
- 关于stringGrid控件的一些疑问
- 请问GetSystemMetrics的用法,是什么意思
- *************在关闭计算机或重启计算机的时候,怎样执行DELPHI程序里的ONCLOSE事件呢*****************
[email protected]
昨天公司维修停电,没能及时赶到csdn,向各位大虾请教
谢谢Brand1(孤独的人),
if(code39[pos][0] = FnewValue[i] then
这一句没看懂,FnewValue是什么?
有没有原码
能在专用打印机上实现,已在一家鞋廠實際使用, 請把mail告我
liang lin
2001.09.21