我的APPLICATION的功能是把串口通信的功能做成了DLL调用,而
其他对数据库操作等功能用Delohi完成。众所周知,串口打开时
调用CreateFile() 返回一句柄hCom ,通信的各功能完成后,
调用CloseHandle(hCom)要把串口关闭;我的DLL内把hCom作为
全局变量在DLL内使用。
为了程序的流程明了、易读。我把实现不同功能的部分放在子
程序中,通信的大概结构如下图:主程序A... 打开串口、拨号子程序B
...
串口通信子程序C
....
通信日志处理子程序D ...
但是我调试时发现了很奇怪的问题,恕我知识浅薄,我这么认为;
在串口通信子程序C中把通信得来的数据在窗体上用Tmemo显示时,
调用Memo1.lines.Add()时,
---------------------------
Debugger Exception Notification
---------------------------
Project RemoteComm.exe raised exception class EAccessViolation
with message 'Access violation at address 0048A018 in module
'REMOTECOMM.EXE'. Read of address E104A41F'. Process stopped.
Use Step or Run to continue.
---------------------------
OK Help
---------------------------但当我把打开串口、拨号子程序B放在主程序内直接使用时,接下来的
串口通信子程序C把通信得来的数据在窗体上用Tmemo显示时,
调用Memo1.lines.Add()时,原来的错误不再出现,但是通信日志处理
子程序D中
//查询通信日志的最大编号
Try
With Query_Log Do
begin
close;
sql.Clear;
sql.Add('Select max(LogId) as LLid From T_CommLog');
prepare;
open;
end;
Except end; 调用Close方法却又出错了,我晕。---------------------------
Debugger Exception Notification
---------------------------
Project RemoteComm.exe raised exception class EAccessViolation
with message 'Access violation at address 0046E736 in module
'REMOTECOMM.EXE'. Read of address 9FA0E8F0'. Process stopped.
Use Step or Run to continue.
---------------------------
OK Help
---------------------------
其他对数据库操作等功能用Delohi完成。众所周知,串口打开时
调用CreateFile() 返回一句柄hCom ,通信的各功能完成后,
调用CloseHandle(hCom)要把串口关闭;我的DLL内把hCom作为
全局变量在DLL内使用。
为了程序的流程明了、易读。我把实现不同功能的部分放在子
程序中,通信的大概结构如下图:主程序A... 打开串口、拨号子程序B
...
串口通信子程序C
....
通信日志处理子程序D ...
但是我调试时发现了很奇怪的问题,恕我知识浅薄,我这么认为;
在串口通信子程序C中把通信得来的数据在窗体上用Tmemo显示时,
调用Memo1.lines.Add()时,
---------------------------
Debugger Exception Notification
---------------------------
Project RemoteComm.exe raised exception class EAccessViolation
with message 'Access violation at address 0048A018 in module
'REMOTECOMM.EXE'. Read of address E104A41F'. Process stopped.
Use Step or Run to continue.
---------------------------
OK Help
---------------------------但当我把打开串口、拨号子程序B放在主程序内直接使用时,接下来的
串口通信子程序C把通信得来的数据在窗体上用Tmemo显示时,
调用Memo1.lines.Add()时,原来的错误不再出现,但是通信日志处理
子程序D中
//查询通信日志的最大编号
Try
With Query_Log Do
begin
close;
sql.Clear;
sql.Add('Select max(LogId) as LLid From T_CommLog');
prepare;
open;
end;
Except end; 调用Close方法却又出错了,我晕。---------------------------
Debugger Exception Notification
---------------------------
Project RemoteComm.exe raised exception class EAccessViolation
with message 'Access violation at address 0046E736 in module
'REMOTECOMM.EXE'. Read of address 9FA0E8F0'. Process stopped.
Use Step or Run to continue.
---------------------------
OK Help
---------------------------
的主程序要带包编译。
如果你的 Query_Log放在Dll中,那么出错才是对的,如果不出错,那么delphi要么太神奇,要么就有问题。你可以把Query_Log放在bpl中,就会一切ok .
或许我没说清楚,我的DLL是VC做的Delphi只是调用