Nizboo 你好。
下面就是“指纹识别系统”的‘delphi“演示程序的代码。在代码中间,在保存用户信息的时候
演示程序演示了一个“edit”用一维数组向IC卡中写数据,他是一个一个字符向IC卡中写。
现在我要做的就是假设现在我有四个编辑框“edit1~edit4”,我怎么才能把四个编辑框的内容写到数组中去呢。取出来
的时候怎么把内容写到“edit5~edit8中去呢。
我今天用的是采用的方法是这样,可以写数据,但是我没办法读数据,读出来就出错。我
首先定义: idata arry [1..4] of string;
写入数据:
infolen := Length(edit1.Text)+Length(edit2.Text)+Length(edit3.Text ))+Length(edit4.Text );;
if infolen=0 then
MessageBox(Form1.Handle,'请输入持卡人信息','提示',MB_OK or MB_ICONINFORMATION)
else
begin
idata[1]:=edit1.text;
idata[2]:=edit2.text;
idata[3]:=edit3.text;
idata[4]:=edit4.text;
MyInfo.Length := infolen;
MyInfo.InfoData := @iData;
pwd := '123456';
retcode := TSFID_WriteUserInfo(10*1000,6,@pwd,MyInfo);
eRSI.Text := IntToHex(retcode,2);
showmessage('信息成功!');
// 写入数据成功
读数据 begin
MyInfo.Length := 0;
MyInfo.InfoData := @iData;
retcode:=TSFID_ReadUserInfo(10*1000,0,0,@Passwd,@MyInfo);
eVU.Text := IntToHex(retcode,2);
if(retcode<>0) then
MessageBox(Form1.Handle,'指纹匹配,但读持卡人信息失败','错误',MB_OK or MB_ICONERROR)
else
begin
edit5.text:=idata[1];
;
edit8.text:=idata[4];
MessageBox(Form1.Handle,'读持卡人信息成功','成功',MB_OK or MB_ICONINFORMATION);
end
下面是演示程序的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
L_Step1: TGroupBox;
BtnConnect: TButton;
L_PORT: TLabel;
ePort: TEdit;
L_Baud: TLabel;
eBaud: TEdit;
L_C: TLabel;
eCR: TEdit;
L_Step2: TGroupBox;
L_VU: TLabel;
eVU: TEdit;
Btn_CC: TButton;
Panel2: TPanel;
BtnRI: TButton;
BtnRI2: TButton;
L_RI: TLabel;
L_RI2: TLabel;
eRI: TEdit;
e_RI: TEdit;
Panel3: TPanel;
G_Enroll: TGroupBox;
L_WI: TLabel;
eIU: TEdit;
BtnEnroll: TButton;
BtnSI: TButton;
Panel5: TPanel;
S1_Fail: TLabel;
S1_LF: TLabel;
S1_PF: TLabel;
L_S1: TLabel;
L_S2: TLabel;
S2_PF: TLabel;
S2_LF: TLabel;
S2_Fail: TLabel;
S3_Fail: TLabel;
S3_LF: TLabel;
S3_PF: TLabel;
L_S3: TLabel;
L_GT: TLabel;
GT_Success: TLabel;
GT_Fail: TLabel;
S1_Success: TLabel;
S2_Success: TLabel;
S3_Success: TLabel;
L_SI: TLabel;
eRSI: TEdit;
BtnST: TButton;
L_RST: TLabel;
eST: TEdit;
L_ITN: TLabel;
eTN: TEdit;
Panel4: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Edit1: TEdit;
Edit2: TEdit;
procedure BtnConnectClick(Sender: TObject);
procedure Btn_CCClick(Sender: TObject);
procedure BtnRI2Click(Sender: TObject);
procedure BtnEnrollClick(Sender: TObject);
procedure BtnRIClick(Sender: TObject);
procedure BtnSIClick(Sender: TObject);
procedure BtnSTClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{=============TSFIDAPI 结构定义==========}
type TSFIDAPI_INFO = record
Length : Integer;
InfoData : Pointer;
end;
type TSFIDAPI_BIR = record
Number : Integer;
BirData : Pointer;
end;
type TSFIDAPI_IC_STAT = record
HasMainFile : Integer;
HasUserApp : Integer;
HasUserInfo : Integer;
HasUserTemplate: Integer;
fpNumber : Integer;
uFingerNum : array[0..3] of char;
UserMatched : Integer;
end;
{==============结构定义完毕==========}
{==========引用声明=================}
function TSFID_Connect(commPort
ointer;curBaud
ointer):Integer;
stdcall;
external 'TSFIDAPI.dll';
Procedure TSFID_CloseConnect;stdcall;external 'TSFIDAPI.dll';
function TSFID_VerifyUser(overTimes:Longword):Integer;
stdcall;
external 'TSFIDAPI.dll';
function TSFID_ReadUserInfo(overTimes:Longword;condition:Integer;pwdlen:Integer;passwd
ointer;info
ointer):Integer;
stdcall;
external 'TSFIDAPI.dll';
function TSFID_ICStatues(overTimes:Longword;ics
ointer):Integer;
stdcall;
external 'TSFIDAPI.dll';
function TSFID_WriteUserInfo(overTimes:Longword;pwdlen:Integer;passwd
ointer;info:TSFIDAPI_INFO):Integer;
stdcall;
external 'TSFIDAPI.dll';
function TSFID_Enroll(order:Integer):Integer;
stdcall;
external 'TSFIDAPI.dll';
function TSFID_WaitEnrollRsp(overTimes:Longword;rsp
ointer;more
ointer):Integer;
stdcall;
external 'TSFIDAPI.dll';
function TSFID_GenerateTemplate(overTimes:Longword;bir
ointer):Integer;
stdcall;
external 'TSFIDAPI.dll';
function TSFID_ModifyUserTemplate(overTimes:Longword;pwdlen:Integer;passwd
ointer;tNo:Integer;fNo:Integer;bir:TSFIDAPI_BIR):Integer;
stdcall;
external 'TSFIDAPI.dll';
{============引用声明结束=============}
var
Form1: TForm1;
I : Integer;
retcode:Integer;
Ics : TSFIDAPI_IC_STAT;
bir : TSFIDAPI_BIR;
iData : array[0..511] of Char;
MyInfo: TSFIDAPI_INFO;
pwd: array[0..6] of Char;
implementation
{$R *.DFM}
procedure TForm1.BtnConnectClick(Sender: TObject);
var
Commid:Integer;
Curbaud:Longword;
begin
retcode:=TSFID_Connect(@Commid,@Curbaud);
//调用TSFID_CONNECT,该函数自动探测通讯端口:
//探测到的端口号和使用的波特率返回,之后可以进行操作
eCR.Text := IntToHex(retcode,2);
//返回值
if(retcode<>0) then
begin
MessageBox(Form1.Handle,'建立连接失败','错误',MB_OK or MB_ICONERROR);
TSFID_CloseConnect;
end
else
begin
ePort.Text := IntToStr(Commid);
//端口
eBaud.Text := IntToStr(CurBaud);
//波特率
L_Step1.Enabled := False;
L_C.Enabled := False;
BtnConnect.Enabled :=False;
L_Port.Enabled := False;
L_Baud.Enabled :=False;
eCR.Enabled := False;
ePort.Enabled :=False;
eBaud.Enabled :=False;
retcode := TSFID_ICStatues(10*1000,@Ics);// 查询IC卡的状态 (整型)
eCR.Text := IntToHex(retcode,2);
//改变返回值的数值进位
if retcode<>0 then
begin
MessageBox(Form1.Handle,'查询卡状态失败,请检查返回值','失败',MB_OK or MB_ICONERROR);
end
else
begin
if Ics.HasUserApp<>1 then
//真值表示持卡人的应用目录已经建立
begin
MessageBox(Form1.Handle,'该卡未经初始化或者非本系统支持卡','错误',MB_OK or MB_ICONERROR);
end
else
begin
{使能登记部分}
L_WI.Enabled := True;
//输入持卡人信息
eIU.Enabled := True;
BtnEnroll.Enabled := True;
//登记一个指纹模板
BtnSI.Enabled := True;
//保持持卡人信息
L_SI.Enabled := True;
//返回值
eRSI.Enabled := True;
//返回值
{使能验证部分}
if Ics.HasUserInfo=1 then
//真值表示已经保持持卡人的专有信息
begin
BtnRI2.Enabled := True;
//条件一,读持卡人信息
if Ics.HasUserTemplate = 1 then
//真值已经登记了持卡人模板
BtnRI.Enabled := True;
//条件0读持卡人信息
end;
L_VU.Enabled := BtnRI.Enabled ;
eVU.Enabled := BtnRI.Enabled ;
L_RI.Enabled := BtnRI2.Enabled ;
eRI.Enabled := BtnRI2.Enabled;
L_RI2.Enabled := BtnRI2.Enabled ;
e_RI.Enabled := L_RI2.Enabled ;
end
end
end
end;
procedure TForm1.Btn_CCClick(Sender: TObject);
begin
TSFID_CloseConnect;
//关闭系统
Application.Terminate;
end;
procedure TForm1.BtnRI2Click(Sender: TObject);
//条件1读持卡人信息
var
ki : Integer;
begin
For ki:=0 to 511 do
iData[ki] := #0;
MyInfo.Length := 0;
//信息保存在EIU里面
MyInfo.InfoData := @iData;
pwd :='123456';
retcode:=TSFID_ReadUserInfo(10*1000,1,6,@pwd,@MyInfo);
//读用户信息
eRI.Text := IntToHex(retcode,2);
if(retcode<>0) then
MessageBox(Form1.Handle,'读持卡人信息失败','错误',MB_OK or MB_ICONERROR)
else
begin
e_RI.Text :='长度='+IntToStr(MyInfo.Length)+' 数据:'+iData;
MessageBox(Form1.Handle,'读持卡人信息成功','成功',MB_OK or MB_ICONINFORMATION);
end
end;
procedure TForm1.BtnEnrollClick(Sender: TObject);
var
order : Integer;
rsp : Integer;
more : Integer;
eloop : Boolean;
begin
L_S1.Visible := False;
L_S2.Visible := False;
L_S3.Visible := False;
S1_PF.Visible := False;
S2_PF.Visible := False;
S3_PF.Visible := False;
S1_LF.Visible := False;
S2_LF.Visible := False;
S3_LF.Visible := False;
S1_Success.Visible := False;
S2_Success.Visible := False;
S3_Success.Visible := False;
S1_Fail.Visible := False;
S2_Fail.Visible := False;
S3_Fail.Visible := False;
L_GT.Visible := False;
GT_Fail.Visible := False;
GT_Success.Visible := False;
Panel5.Repaint;
L_ITN.Enabled := False;
BtnST.Enabled := False;
L_RST.Enabled :=False;
eST.Enabled := False;
eTN.Enabled := False;
eloop := True;
for order:=1 to 3 do
begin
if order=1 then
L_S1.Visible :=True
else
if order=2 then
L_S2.Visible := True
else
L_S3.Visible := True;
Panel5.Repaint;
retcode := TSFID_Enroll(order);
while True do
begin
retcode := TSFID_WaitEnrollRsp(25*1000,@rsp,@more);
if retcode<>0 then
begin
MessageBox(Form1.Handle,'登记模板失败','失败',MB_OK or MB_ICONERROR);
eloop:=False;
break;
end
else
if rsp=1 then
begin
if order=1 then
S1_PF.Visible := True
else
if order=2 then
S2_PF.Visible := True
else
S3_PF.Visible := True;
Panel5.Repaint;
end
else
if rsp=2 then
begin
if order=1 then
S1_LF.Visible := True
else
if order=2 then
S2_LF.Visible := True
else
S3_LF.Visible := True;
Panel5.Repaint;
end
else
if rsp=5 then
begin
if order=1 then
S1_Success.Visible := True
else
if order=2 then
S2_Success.Visible := True
else
S3_Success.Visible := True;
Panel5.Repaint;
break;
end
else
begin
if order=1 then
S1_Fail.Visible := True
else
if order=2 then
S2_Fail.Visible := True
else
S3_Fail.Visible := True;
Panel5.Repaint;
eloop := False;
Break;
end
end;
if eloop = False then
break;
end;
if eloop = True then
begin
L_GT.Visible := True;
Panel5.Repaint;
bir.BirData := @iData;
retcode := TSFID_GenerateTemplate(10*1000,@bir);
//采用三次采样的样本生成的模板
if retcode<>0 then
GT_Fail.Visible := True
else
begin
GT_Success.Visible := True;
L_ITN.Enabled := True;
BtnST.Enabled := True;
L_RST.Enabled :=True;
eST.Enabled := True;
eTN.Enabled := True;
end;
Panel5.Repaint;
end
end;
procedure TForm1.BtnRIClick(Sender: TObject);
// 条件0 读卡人信息
var
Passwd: array[0..5] of Char;
ki : Integer;
begin
For ki:=0 to 511 do
iData[ki] := #0;
MessageBox(Form1.Handle,'持卡人指纹需匹配才能读取卡中信息!请使用干净无汗、无龟裂的手指,推荐食指或中指!红、黄指示灯熄灭或者听到语音提示后,请放手指!','提示',MB_OK or MB_ICONINFORMATION);
retcode := TSFID_VerifyUser(15*1000);
//采集持卡人指纹样本,校验持卡人身份。 int TSFID_verifyuser(DWORD overtimes)
e_RI.Text:= IntToHex(retcode,2);
if(retcode<>0) then
begin
MessageBox(Form1.Handle,'身份验证失败','错误',MB_OK or MB_ICONERROR);
end
else
begin
MyInfo.Length := 0;
MyInfo.InfoData := @iData;
retcode:=TSFID_ReadUserInfo(10*1000,0,0,@Passwd,@MyInfo);
eVU.Text := IntToHex(retcode,2);
if(retcode<>0) then
MessageBox(Form1.Handle,'指纹匹配,但读持卡人信息失败','错误',MB_OK or MB_ICONERROR)
else
begin
e_RI.Text :='长度='+IntToStr(MyInfo.Length)+' 数据:'+iData;
MessageBox(Form1.Handle,'读持卡人信息成功','成功',MB_OK or MB_ICONINFORMATION);
end
end
end;
procedure TForm1.BtnSIClick(Sender: TObject);
//保存持卡人信息
var
infolen : Integer;
ki : Integer;
begin
For ki:=0 to 511 do
iData[ki] := #0;
infolen := Length(eIU.Text)+Length(edit1.Text)+Length(edit2.Text );
if infolen=0 then
MessageBox(Form1.Handle,'请输入持卡人信息','提示',MB_OK or MB_ICONINFORMATION)
else
begin
for ki:=0 to infolen-1 do
iData[ki] := eIU.Text[ki+1];
iData[ki+1] :=edit1.text[ki];
iData[ki+2] :=edit2.text[ki+1];
MyInfo.Length := infolen;
MyInfo.InfoData := @iData;
pwd := '123456';
retcode := TSFID_WriteUserInfo(10*1000,6,@pwd,MyInfo);
eRSI.Text := IntToHex(retcode,2);
showmessage('保存考生信息成功!');
end
end;
procedure TForm1.BtnSTClick(Sender: TObject);
var
tnum : Integer;
begin
if Length(eTN.Text)=0 then
MessageBox(Form1.Handle,'请输入模板号','提示',MB_OK or MB_ICONINFORMATION)
else
begin
tnum := StrToInt(eTN.Text);
if (tnum<1) or (tnum>4) then
MessageBox(Form1.Handle,'模板号非法,有效值:1-4','提示',MB_OK or MB_ICONINFORMATION)
else
begin
pwd :='123456';
retcode := TSFID_ModifyUserTemplate(10*1000,6,@pwd,tnum,0,bir);
eST.Text := IntToHex(retcode,2);
if retcode<>0 then
MessageBox(Form1.Handle,'保存模板失败','错误',MB_OK or MB_ICONERROR)
else
MessageBox(Form1.Handle,'保存模板成功','成功',MB_OK or MB_ICONINFORMATION)
end
end
end;
end.