V
vicchen0
Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序有这样一段代码:
while Scan_IsButtonDown() = false do
begin
Application.ProcessMessages; //释放CPU
end;
上边的Scan_IscButtonDown是用外部设备传递过来的消息,如果没有按钮他就一直在死循环,现在我想在界面上做一个退出按钮,就是说如果我按钮那个退出按钮就退出程序,上边的代码是在下面这段程序里边的。
还有别一个关于Dll文件加载的问题,我想问下面的这段代码,如果我的DLL文件加载不成功,我想他可以再刷次就使用,要怎么做才可以呢?还有就是如果识别失败的话,我的程序就再也不能用了,程序就一直死在那里,请问有什么方法可以释放那个DLL文件然后再重新加载呢?或者说如果在“识别失败”后能够再次能够再识别,我现在的情况是一失败之后,整个程序就再也不能用了,无论怎么按也没有反应的
procedure TForm1.Button1Click(Sender: TObject);
var
result: Integer;
I: Integer;
j: Integer;
bGoon: WordBool;
length: Integer;
strImageFile: AnsiString;
strHeadFile: AnsiString;
strResult: string;
buffer: PChar;
len: Integer;
HInst: THandle;
//--------函数指针--------------------------------------
FPointer: TFarProc;
LoadIdcardLibrary: TLoadIdcardLibrary;
Scan_IsButtonDown: TScan_IsButtonDown;
RecogIdcard: TRecogIdcard;
FreeIdcardLibrary: TFreeIdcardLibrary;
//-------------------------------------------------------
pSysDirChar;
SysDir:String;
begin
//--------取得系统目录,之前已将扫描驱动相关文件拷贝到这个目录下
GetMem(pSysDir,80);
i:=GetSystemDirectory(pSysDir,80);
if i<80 then
pSysDir:=#0;
SysDir := StrPas(pSysDir);
FreeMem(pSysDir);
SetCurrentDir(SysDir);//设置软件运行目录为系统目录
HInst := LoadLibrary(PChar(SysDir+'/idcarddll.dll'));//加载驱动DLL
if HInst > 0 then//如果加载成功
begin
try
FPointer := GetProcAddress(HInst, 'LoadIdcardLibrary');//指定函数指针
if FPointer <> nil then
begin
LoadIdcardLibrary := TLoadIdcardLibrary(FPointer);//类型转换
FPointer := nil;
end;
FPointer := GetProcAddress(HInst, 'Scan_IsButtonDown');
if FPointer <> nil then
begin
Scan_IsButtonDown := TScan_IsButtonDown(FPointer);
FPointer := nil;
end;
FPointer := GetProcAddress(HInst, 'RecogIdcard');
if FPointer <> nil then
begin
RecogIdcard := TRecogIdcard(FPointer);
FPointer := nil;
end;
FPointer := GetProcAddress(HInst, 'FreeIdcardLibrary');
if FPointer <> nil then
begin
FreeIdcardLibrary := TFreeIdcardLibrary(FPointer);
FPointer := nil;
end;
//加载识别核心
if (LoadIdcardLibrary() = 0) then
begin
Edit2.Text := '成功初始化,请按扫描机器上的按钮进行扫描!' ;
button1.Enabled:=false;
EditName.Text := '';
EditSex.Text := '';
EditMZ.Text := '';
EditBD.Text := '';
EditAddr.Text := '';
EditID.Text := '';
EditName.Refresh;
EditSex.Refresh;
EditMZ.Refresh;
EditBD.Refresh;
EditAddr.Refresh;
EditID.Refresh;
//进行识别
length := 31;
bGoon := True;
while bGoon do
begin
strImageFile := 'd:/ID00';
strImageFile := strImageFile + IntToStr(num);
strImageFile := strImageFile + '.jpg';
strHeadFile := 'd:/ID00';
strHeadFile := strHeadFile + IntToStr(num);
strHeadFile := strHeadFile + '_head.jpg';
while Scan_IsButtonDown() = false do
begin
Application.ProcessMessages; //释放CPU
end;
Edit2.Text := '正在扫描...';
Edit2.Refresh;
result := RecogIdcard(strImageFile, @MyCard, True, 0, length,
strHeadFile);
//image1.Picture.LoadFromFile( strImageFile);
if (result = 0) then //识别成功
begin
num:=num+1;
//写姓名
Editname.Text := 姓名;
//写性别
EditSex.Text := 性别;
Edit2.Text := '成功识别!';
end
else //识别失败
begin
Edit2.Text := '识别失败!';
button3.Enabled:=false;
button1.Caption:='重新扫描';
button1.Enabled:=true;
exit;
end;
bGoon := true;
end;
FreeLibrary(HInst);
end
else
begin
Edit2.Text := '初始化失败,请刷新网页!';
end;
finally
FreeLibrary(HInst);//释放驱动DLL
end;
end
else
ShowMessage('不能装载“idcarddll.dll” 文件');
end;
while Scan_IsButtonDown() = false do
begin
Application.ProcessMessages; //释放CPU
end;
上边的Scan_IscButtonDown是用外部设备传递过来的消息,如果没有按钮他就一直在死循环,现在我想在界面上做一个退出按钮,就是说如果我按钮那个退出按钮就退出程序,上边的代码是在下面这段程序里边的。
还有别一个关于Dll文件加载的问题,我想问下面的这段代码,如果我的DLL文件加载不成功,我想他可以再刷次就使用,要怎么做才可以呢?还有就是如果识别失败的话,我的程序就再也不能用了,程序就一直死在那里,请问有什么方法可以释放那个DLL文件然后再重新加载呢?或者说如果在“识别失败”后能够再次能够再识别,我现在的情况是一失败之后,整个程序就再也不能用了,无论怎么按也没有反应的
procedure TForm1.Button1Click(Sender: TObject);
var
result: Integer;
I: Integer;
j: Integer;
bGoon: WordBool;
length: Integer;
strImageFile: AnsiString;
strHeadFile: AnsiString;
strResult: string;
buffer: PChar;
len: Integer;
HInst: THandle;
//--------函数指针--------------------------------------
FPointer: TFarProc;
LoadIdcardLibrary: TLoadIdcardLibrary;
Scan_IsButtonDown: TScan_IsButtonDown;
RecogIdcard: TRecogIdcard;
FreeIdcardLibrary: TFreeIdcardLibrary;
//-------------------------------------------------------
pSysDirChar;
SysDir:String;
begin
//--------取得系统目录,之前已将扫描驱动相关文件拷贝到这个目录下
GetMem(pSysDir,80);
i:=GetSystemDirectory(pSysDir,80);
if i<80 then
pSysDir:=#0;
SysDir := StrPas(pSysDir);
FreeMem(pSysDir);
SetCurrentDir(SysDir);//设置软件运行目录为系统目录
HInst := LoadLibrary(PChar(SysDir+'/idcarddll.dll'));//加载驱动DLL
if HInst > 0 then//如果加载成功
begin
try
FPointer := GetProcAddress(HInst, 'LoadIdcardLibrary');//指定函数指针
if FPointer <> nil then
begin
LoadIdcardLibrary := TLoadIdcardLibrary(FPointer);//类型转换
FPointer := nil;
end;
FPointer := GetProcAddress(HInst, 'Scan_IsButtonDown');
if FPointer <> nil then
begin
Scan_IsButtonDown := TScan_IsButtonDown(FPointer);
FPointer := nil;
end;
FPointer := GetProcAddress(HInst, 'RecogIdcard');
if FPointer <> nil then
begin
RecogIdcard := TRecogIdcard(FPointer);
FPointer := nil;
end;
FPointer := GetProcAddress(HInst, 'FreeIdcardLibrary');
if FPointer <> nil then
begin
FreeIdcardLibrary := TFreeIdcardLibrary(FPointer);
FPointer := nil;
end;
//加载识别核心
if (LoadIdcardLibrary() = 0) then
begin
Edit2.Text := '成功初始化,请按扫描机器上的按钮进行扫描!' ;
button1.Enabled:=false;
EditName.Text := '';
EditSex.Text := '';
EditMZ.Text := '';
EditBD.Text := '';
EditAddr.Text := '';
EditID.Text := '';
EditName.Refresh;
EditSex.Refresh;
EditMZ.Refresh;
EditBD.Refresh;
EditAddr.Refresh;
EditID.Refresh;
//进行识别
length := 31;
bGoon := True;
while bGoon do
begin
strImageFile := 'd:/ID00';
strImageFile := strImageFile + IntToStr(num);
strImageFile := strImageFile + '.jpg';
strHeadFile := 'd:/ID00';
strHeadFile := strHeadFile + IntToStr(num);
strHeadFile := strHeadFile + '_head.jpg';
while Scan_IsButtonDown() = false do
begin
Application.ProcessMessages; //释放CPU
end;
Edit2.Text := '正在扫描...';
Edit2.Refresh;
result := RecogIdcard(strImageFile, @MyCard, True, 0, length,
strHeadFile);
//image1.Picture.LoadFromFile( strImageFile);
if (result = 0) then //识别成功
begin
num:=num+1;
//写姓名
Editname.Text := 姓名;
//写性别
EditSex.Text := 性别;
Edit2.Text := '成功识别!';
end
else //识别失败
begin
Edit2.Text := '识别失败!';
button3.Enabled:=false;
button1.Caption:='重新扫描';
button1.Enabled:=true;
exit;
end;
bGoon := true;
end;
FreeLibrary(HInst);
end
else
begin
Edit2.Text := '初始化失败,请刷新网页!';
end;
finally
FreeLibrary(HInst);//释放驱动DLL
end;
end
else
ShowMessage('不能装载“idcarddll.dll” 文件');
end;