在写三层程序(使用SocketConnection与服务端连接)时有如下一段代码,
procedure TForm1.Button3Click(Sender: TObject);
var
i : Shortint;
begin
for i:=1 to 3 do begin
ServerConnection.Connected:=True;
ClientDataSet1.Data:=ServerConnection.AppServer.GetVendotList;
ServerConnection.Connected:=False;
end;
end;
当循环终值大于1时,程序会被异常终止,并弹出一对话框:
Debugger Exception Notification
Project TestProject.exe raised exception class
Exception with message 'Access violation at address
0048CCFA in module 'ScktSrvr4Hit.exe'. Read of address 00000000'.
Process stopped. Use Step or Run to continue.
若将与服务端的连接写到循环之外,则程序可以正常运行,不会出现任何异常情况。
procedure TForm1.Button3Click(Sender: TObject);
var
i : Shortint;
begin
for i:=1 to 3 do begin
ServerConnection.Connected:=True;
ClientDataSet1.Data:=ServerConnection.AppServer.GetVendotList;
ServerConnection.Connected:=False;
end;
end;
当循环终值大于1时,程序会被异常终止,并弹出一对话框:
Debugger Exception Notification
Project TestProject.exe raised exception class
Exception with message 'Access violation at address
0048CCFA in module 'ScktSrvr4Hit.exe'. Read of address 00000000'.
Process stopped. Use Step or Run to continue.
若将与服务端的连接写到循环之外,则程序可以正常运行,不会出现任何异常情况。
解决方案 »
- 在DBGrideh中新增记录之前查看来记录的字段是否有空,没有就新增,有就不能新增。
- 一个问题:如何隐藏程序和进程?
- ***************数据的发送和接收
- 请问如何右键点击选中grid中的一列,然后修改此列的值
- 这个难题可称为世界之最了.大家进来帮我看看.delphi回调VC动态库返回不了结果啦...
- 请问:如何安装calcomp控件?
- 关于系统热键(Ctrl+鼠标滚轮)的问题
- ※※ ¥8000 ~¥12000月薪能招到什么样的程序员? ※※
- MDI 如何使MDIChild 显示在 Design位置 (Just here waiting)
- 做共享软件挣钱吗?[讨论]
- 如何提取ADOqery数据处理异常时的错误代码?
- 如何将一个数据记录集中的数据,导入到Excel文件中
分析:for i:=1 to 3 do begin
ServerConnection.Connected:=True;
ClientDataSet1.Data:=ServerConnection.AppServer.GetVendotList;
ServerConnection.Connected:=False;
end;
你这样等于在连续打开关闭连接。这样服务器端在不断的申请、释放资源。在资源还没释放时,又要申请,造成冲突。
我没有测试,只是感觉这样。加上sleep试一下或者干脆在每次循环后加上一个:弹出对话框。试试,这样可以看出是不是由于关闭和打开之间没有时间间隔造成的。