unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Memo1: TMemo;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Image1: TImage;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Label5: TLabel;
    Label6: TLabel;
    Edit4: TEdit;
    Edit5: TEdit;
    GroupBox2: TGroupBox;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    CurrentDir:string;
  public
    { Public declarations }
  end;


TMakeBar = procedure(Data_Pt:PChar;DataLen:integer;FileName:PChar;nClumn,nErr,nHLRatio,nHeight:integer);stdcall;
//(PCHAR ucData, long nDataLen, char* szBmpFileName,
// long nClumn, long , long );
TMixText = procedure(nFileName:PChar;mFileName:Pchar;szText:PChar;lFontSize,lTxtHeight,lHmargin,lVmargin,lTxtCntOneLine:integer); stdcall;
var
  Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
Moudle: THandle;
Makebar:TMakebar;
MixText:TMixText;
StrPt,FilePt:PChar;
sText:PChar;
Txt:String;
begin
Moudle:=LoadLibrary('MakePdf417.dll');
@Makebar:=GetProcAddress(Moudle,'Make');
@MixText:=GetProcAddress(Moudle,'MixText');
Txt:=Memo1.Lines.Text;
StrPt:=PChar(Txt);
sText:=PChar(Edit7.Text);

FilePt:=PChar(String('temp.bmp'));
Makebar(StrPt,Length(Txt),FilePt,StrToInt(Edit1.Text),
StrToInt(Edit2.Text),StrToInt(Edit3.Text),StrToInt(Edit5.Text));
MixText( FilePt,FilePt,sText,StrToInt(Edit8.Text),
StrToInt(Edit9.Text),StrToInt(Edit10.Text),StrToInt(Edit11.Text),StrToInt(Edit6.Text));
Image1.Picture.LoadFromFile('temp.bmp');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  Moudle: THandle;
  Makebar:TMakebar;
  MixText:TMixText;
  StrPt,FilePt:PChar;
  Txt:string;

begin
   //CurrentDir := GetCurrentDir();
   OpenDialog1.InitialDir := CurrentDir;
   //CreateDir(CurrentDir+'\\bmp\\');
   if OpenDialog1.Execute then
      Memo1.Lines.LoadFromFile(OpenDialog1.FileName)
   else
      Memo1.Lines.Clear;
   Moudle:=LoadLibrary('MakePdf417.dll');
   @Makebar:=GetProcAddress(Moudle,'Make');
   @MixText:=GetProcAddress(Moudle,'MixText');
   Txt:=Memo1.Lines.Text;
   StrPt:=PChar(Txt);
   FilePt:=PChar(String('temp.bmp'));
   Makebar(StrPt,Length(Txt),FilePt,StrToInt(Edit1.Text),
   StrToInt(Edit2.Text),StrToInt(Edit3.Text),StrToInt(Edit5.Text));
   MixText( FilePt,FilePt, StrPt,StrToInt(Edit8.Text),StrToInt(Edit9.Text),StrToInt(Edit10.Text),
   StrToInt(Edit11.Text),StrToInt(Edit6.Text));
   Image1.Picture.LoadFromFile('temp.bmp');

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   CurrentDir := GetCurrentDir();
end;

procedure TForm1.Button3Click(Sender: TObject);
var
   //CurrentDir:string;
   NewFile: TFileStream;
   OldFile: TFileStream;

begin
   //CurrentDir := GetCurrentDir();
   CreateDir(CurrentDir+'\\bmp\\');
   SaveDialog1.InitialDir := CurrentDir + '\\bmp\\';
   SaveDialog1.FileName := 'barcode.bmp';
   SaveDialog1.Filter := '位图文件 (*.bmp)|*.bmp|所有文件 (*.*)|*.*||';
   SaveDialog1.Title := '另存为';
   if (SaveDialog1.Execute()) then
   begin
      OldFile := TFileStream.Create(CurrentDir+'\\temp.bmp', fmOpenRead);
      try
         NewFile := TFileStream.Create(SaveDialog1.FileName, fmCreate);
         try
            NewFile.CopyFrom(OldFile, OldFile.Size);
         finally
            FreeAndNil(NewFile);
         end;
      finally
         FreeAndNil(OldFile);
      end;
   end;

end;

end.
