ubarcodeform.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. unit ubarcodeform;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, StBarC, ExtCtrls, ComCtrls, Typinfo;
  6. type
  7. TfmBarCodeForm = class(TForm)
  8. pnTop: TPanel;
  9. StBarCode1: TStBarCode;
  10. pnBottom: TPanel;
  11. sb: TStatusBar;
  12. pnB1: TPanel;
  13. lbValue: TLabel;
  14. edValue: TEdit;
  15. pnB2: TPanel;
  16. lbSize: TLabel;
  17. edSize: TEdit;
  18. udBarWidth: TUpDown;
  19. pnB3: TPanel;
  20. lbFormat: TLabel;
  21. coBarCodeType: TComboBox;
  22. coCode128Subsets: TComboBox;
  23. pnB4: TPanel;
  24. cbShowCode: TCheckBox;
  25. cbAddCheckChar: TCheckBox;
  26. pnBLast: TPanel;
  27. Button1: TButton;
  28. Label1: TLabel;
  29. edFontSize: TEdit;
  30. udFotnSize: TUpDown;
  31. procedure Button1Click(Sender: TObject);
  32. procedure edValueChange(Sender: TObject);
  33. procedure cbShowCodeClick(Sender: TObject);
  34. procedure edSizeChange(Sender: TObject);
  35. procedure FormResize(Sender: TObject);
  36. procedure FormCreate(Sender: TObject);
  37. procedure coBarCodeTypeChange(Sender: TObject);
  38. procedure cbAddCheckCharClick(Sender: TObject);
  39. procedure coCode128SubsetsChange(Sender: TObject);
  40. procedure edFontSizeChange(Sender: TObject);
  41. private
  42. { Déclarations privées }
  43. name : String;
  44. version : String;
  45. procedure buildBarCodeTypes();
  46. procedure buildCode128Subsets();
  47. public
  48. { Déclarations publiques }
  49. end;
  50. var
  51. fmBarCodeForm: TfmBarCodeForm;
  52. implementation
  53. uses StrUtils;
  54. {$R *.dfm}
  55. procedure TfmBarCodeForm.Button1Click(Sender: TObject);
  56. begin
  57. StBarCode1.CopyToClipboard ;
  58. end;
  59. procedure TfmBarCodeForm.edValueChange(Sender: TObject);
  60. var s : String;
  61. begin
  62. s := edValue.Text;
  63. {
  64. if (coBarCodeType.ItemIndex = ord(bcEAN_13))
  65. and (length (s) < 12) or (length(s) > 13) then
  66. begin
  67. s := '';
  68. end;
  69. }
  70. StBarCode1.Code := s;
  71. end;
  72. procedure TfmBarCodeForm.cbShowCodeClick(Sender: TObject);
  73. begin
  74. StBarCode1.ShowCode := (sender as TCheckBox).Checked;
  75. end;
  76. procedure TfmBarCodeForm.edSizeChange(Sender: TObject);
  77. begin
  78. StBarCode1.BarWidth := StrToFloat((sender as TEdit).Text);
  79. end;
  80. procedure TfmBarCodeForm.FormResize(Sender: TObject);
  81. begin
  82. self.Caption := self.name + ' - '
  83. + IntToStr(StBarCode1.Width) + 'x' + IntToStr(StBarCode1.Height);
  84. end;
  85. procedure TfmBarCodeForm.coBarCodeTypeChange(Sender: TObject);
  86. var this : TComboBox;
  87. begin
  88. this := sender as TComboBox;
  89. sb.SimpleText := 'Selected ' + IntToStr(this.ItemIndex);
  90. coCode128Subsets.Visible := this.ItemIndex = ord(bcCode128);
  91. StBarCode1.BarCodeType := TStBarCodeType(this.ItemIndex);
  92. end;
  93. procedure TfmBarCodeForm.buildBarCodeTypes();
  94. var i : Integer;
  95. s : String;
  96. begin
  97. for i := ord(low(TstBarCodeType)) to ord(high(TstBarCodeType)) do
  98. begin
  99. s := getEnumName(typeInfo(TStBarCodeType), i);
  100. s := Midstr(s, 3, 100);
  101. coBarCodeType.Items.Add(s);
  102. end;
  103. coBarCodeType.ItemIndex := ord(bcCode39);
  104. StBarCode1.BarCodeType := bcCode39;
  105. end;
  106. procedure TfmBarCodeForm.buildCode128Subsets();
  107. var i : Integer;
  108. s : String;
  109. begin
  110. for i := ord(low(TStCode128CodeSubset)) to ord(high(TStCode128CodeSubset)) do
  111. begin
  112. s := getEnumName(typeInfo(TStCode128CodeSubset), i);
  113. s := Midstr(s, 3, 100);
  114. coCode128Subsets.Items.Add(s);
  115. end;
  116. coCode128Subsets.ItemIndex := ord(csCodeA);
  117. coCode128Subsets.Visible := FALSE;
  118. end;
  119. procedure TfmBarCodeForm.FormCreate(Sender: TObject);
  120. begin
  121. self.version := '$Id: ubarcodeform.pas,v 1.2 2009-04-16 13:30:36 marand Exp $';
  122. self.name := 'OSInet barcode generator';
  123. sb.SimplePanel := True;
  124. sb.SimpleText := self.name + ' - ' + self.version;
  125. buildBarCodeTypes;
  126. buildCode128Subsets;
  127. end;
  128. procedure TfmBarCodeForm.cbAddCheckCharClick(Sender: TObject);
  129. begin
  130. StBarCode1.AddCheckChar := (sender as TCheckBox).Checked;
  131. end;
  132. procedure TfmBarCodeForm.coCode128SubsetsChange(Sender: TObject);
  133. begin
  134. StBarCode1.Code128Subset := TStCode128CodeSubset((sender as TComboBox).ItemIndex);
  135. end;
  136. procedure TfmBarCodeForm.edFontSizeChange(Sender: TObject);
  137. begin
  138. StBarCode1.Font.Size := StrToInt(edFontSize.Text);
  139. end;
  140. end.