我有一个刷卡器的源码,我看不懂,但是我要用,哪位大侠能翻译一下呀??每句都要,详细一些,分不够可以再追加??
unit GHCDLL;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    optSelection: TRadioGroup;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    nTrack: TEdit;
    sOneThree: TEdit;
    sTwo: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);  private
    { Private declarations }
  public
    { Public declarations }
  end;
  Treadcard=function(n1:integer;n2:integer;s1:Pchar;s2:Pchar;n3:integer):integer;stdcall;
  Twritecard=function(n1:integer;n2:integer;s1:Pchar;s2:Pchar;n3:integer):integer;stdcall;
  THandle = Integer;
var
  Form1: TForm1;
  readcard: Treadcard;
  writecard:Twritecard;
implementation{$R *.DFM}procedure TForm1.Button2Click(Sender: TObject);
begin
        Close;
end;procedure TForm1.Button1Click(Sender: TObject);
var
        n,code:Integer;
        sMsg:  String;
        Handle: THandle;
        s1:Array[0..255] of Char;
        s2:Array[0..255] of Char;
        p1:PChar;
        p2:PChar;
begin
        Val(nTrack.Text, n, code);
        if Code <> 0 then
        begin
                MessageDlg('Error at position: ' + IntToStr(Code), mtWarning,[mbOK], 0);
                nTrack.Clear;
                nTrack.SetFocus;
                exit
        end;        if (n<1) or (n>5) then
        begin
                MessageDlg('Error parameters: Track=' + IntToStr(n), mtWarning, [mbOk], 0);
                nTrack.Clear;
                nTrack.SetFocus;
                exit
        end;        Handle :=LoadLibrary('ghc715.DLL');
        if Handle <> 0 then
        begin
                @readcard := GetProcAddress(Handle, 'readcard');
                @writecard:= GetProcAddress(Handle, 'writecard');
                if (@readcard = nil) or (@writecard=nil) then
                begin
                        Application.MessageBox('Load Function error','Error',MB_OK);
                        exit
                end;
                if optSelection.Items[optSelection.ItemIndex] = '读' then
                begin
                        Fillchar(s1,sizeof(s1),0);
                        Fillchar(s2,sizeof(s2),0);
                        p1:=@s1;
                        p2:=@s2;
                        code:=readcard(1,n,p1,p2,2);
                        if code<>0 then
                        begin
                                sMsg:=IntToStr(code);
                                Application.MessageBox(Pchar(sMsg),'Error Reading card',MB_OK);
                        end
                        else
                        begin
                                sOneThree.Text:=String(p2);
                                sTwo.Text:=String(p1);
                                Application.MessageBox('Succeed in reading card','Info',MB_OK)
                        end;
                end
                else
                begin
                        StrPCopy(s2,Pchar(sOneThree.Text));
                        StrPCopy(s1,Pchar(sTwo.Text));
                        p1:=@s1;
                        p2:=@s2;
                        code:=writecard(1,n,p1,p2,2);
                        if code<>0 then
                        begin
                                Application.MessageBox(Pchar(IntToStr(code)),'Error Writing card',MB_OK);
                        end
                        else
                                Application.MessageBox('Succeed in reading card','Info',MB_OK);
                end;
                FreeLibrary(Handle);
        end
        else
        begin
                Application.MessageBox('加载动态连接库错误:ghc715.dll','错误',MB_OK);
                exit;
        end;
        end;
end.

解决方案 »

  1.   

    怎么调用他呀?/在delphi中,他还有一个应用程序
      

  2.   

    Val(nTrack.Text, n, code);//判断ntrack中输入是否为数字
            if Code <> 0 then //不是数字
            begin
                    MessageDlg('Error at position: ' + IntToStr(Code), mtWarning,[mbOK], 0);//提示哪位不是数字
                    nTrack.Clear;清除内容
                    nTrack.SetFocus;定位至ntrackt
                    exit退出等待输入
            end;        if (n<1) or (n>5) then输入为数字如果为<1 或>5 
            begin
                    MessageDlg('Error parameters: Track=' + IntToStr(n), mtWarning, [mbOk], 0);报警提示错误参数
                    nTrack.Clear;同上
                    nTrack.SetFocus;
                    exit
            end;
      

  3.   


            Handle :=LoadLibrary('ghc715.DLL');//加载动态链接库ghc715.dll
            if Handle <> 0 then//调用成功
            begin
                    @readcard := GetProcAddress(Handle, 'readcard');//将readcard函数指向dll中的对应的readcard函数的调用地址
                    @writecard:= GetProcAddress(Handle, 'writecard');//将writercard函数指向dll中的对应的writecard函数的调用地址
                    if (@readcard = nil) or (@writecard=nil) then
                    begin
                            Application.MessageBox('Load Function error','Error',MB_OK);//函数调用错误提示
                            exit退出
                    end;
                    if optSelection.Items[optSelection.ItemIndex] = '读' then
                    begin读卡
                            Fillchar(s1,sizeof(s1),0);//对s1,s2赋初值
                            Fillchar(s2,sizeof(s2),0);
                            p1:=@s1;//取s1,s2 地址
                            p2:=@s2;
                            code:=readcard(1,n,p1,p2,2);//调用readcard,读取的数据在s1,s2中,返回错误码code                        if code<>0 then//有错误发生
                            begin
                                    sMsg:=IntToStr(code);
                                    Application.MessageBox(Pchar(sMsg),'Error Reading card',MB_OK);错误提示
                            end
                            else
                            begin//读卡正确
                                    sOneThree.Text:=String(p2);//将读到数据s1,s2分别赋华丽两个edit
                                    sTwo.Text:=String(p1);
                                    Application.MessageBox('Succeed in reading card','Info',MB_OK)//读卡成功提示
                            end;
                    end
                    else
                    begin//写卡
                            StrPCopy(s2,Pchar(sOneThree.Text));//将两个edti内容赋给s1,s2
                            StrPCopy(s1,Pchar(sTwo.Text));
                            p1:=@s1;//取s1,s2地址
                            p2:=@s2;
                            code:=writecard(1,n,p1,p2,2);//调用写卡函数,将s1,s2中数据写入,返回错误码code
                            if code<>0 then//写卡错误
                            begin
                                    Application.MessageBox(Pchar(IntToStr(code)),'Error Writing card',MB_OK);//错误提示
                            end
                            else//无错误
                                    Application.MessageBox('Succeed in reading card','Info',MB_OK);//成功写入提示
                    end;
                    FreeLibrary(Handle);//释放动态链接库
            end
            else  //handle=0,加载dll错误
            begin
                    Application.MessageBox('加载动态连接库错误:ghc715.dll','错误',MB_OK);//错误提示
                    exit;//退出
            end;
            end;
    end.