Windows 2000 关闭/注销时,应用程序无法终止。

hiflower 2003-12-12 10:32:49
这是 MIDAS 三层中的客户端应用程序。
点 Button1,再点 Button2,或先 Button2,再 Button1 后,Windows 关闭/注销时,此程序不能终止。
服务端程序启动或不启动都无所谓,结果都一样。

高手快来帮忙啊。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBClient, MConnect, SConnect;

type
TForm1 = class(TForm)
Button1: TButton;
SocketConnection1: TSocketConnection;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
try
SocketConnection1.Open;
except
SocketConnection1.Close;
end;
// Application.MessageBox('ddd','ddd');
// MessageBox(Handle,'aaa','ddd',0);
// showmessage('ok');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
// Application.MessageBox('ddd','ddd');
// MessageBox(Handle,'aaa','ddd',0);
showmessage('ok');
end;

end.
...全文
132 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
leapmars 2003-12-22
  • 打赏
  • 举报
回复
SocketConnection 在内部的确使用了消息循环。不管 SupportCallbacks 为何值,在 Open 时都是会建立一个线程来处理 Socket。 不过,出现这种问题,的确很奇怪。
猛禽 2003-12-22
  • 打赏
  • 举报
回复
一般是用不着,我从来都是一放上SOCKETCONNECTION就把它设置为FALSE
hiflower 2003-12-21
  • 打赏
  • 举报
回复
看了看 VCL 源码,当SupportCallbacks 为 True 时,在 Open 时是建立一个线程处理的,大概是这个线程有问题,不想再深入研究了,不开这个属性得了。
qiume 2003-12-15
  • 打赏
  • 举报
回复
//以下是我在WINDOWS的SDK里找的:
callback

[callback [ , function-attr-list] ] type-specifier [ptr-declarator] function-name(
[ [parameter-attribute-list] ] type-specifier [declarator]
, ...
);

function-attr-list

Specifies zero or more attributes that apply to the function. Valid function attributes are local; the pointer attribute ref, unique, or ptr; and the usage attributes string, ignore, and context_handle. Separate multiple attributes with commas.

type-specifier

Specifies a base_type, struct, union, enum type, or type identifier. An optional storage specification can precede type-specifier.

ptr-declarator

Specifies zero or more pointer declarators. A pointer declarator is the same as the pointer declarator used in C; it is constructed from the * designator, modifiers such as far, and the qualifier const.

function-name

Specifies the name of the remote procedure.

parameter-attribute-list

Specifies zero or more directional attributes, field attributes, usage attributes, and pointer attributes appropriate for the specified parameter type. Separate multiple attributes with commas.

declarator

Specifies a standard C declarator such as identifiers, pointer declarators, and array declarators. For more information, see pointers and arrays. The parameter-name identifier is optional.

Example

[callback] void DisplayString([in, string] char * p1);


Remarks

The callback attribute declares a static callback function that exists on the client side of the distributed application. Callback functions provide a way for the server to execute code on the client.
The callback function is useful when the server must obtain information from the client. If server applications were supported on Windows 3.x, the server could make a call to a remote procedure on the Windows 3.x server to obtain the needed information. The callback function accomplishes the same purpose. The callback allows the server to query the client for information in the context of the original call.

Callbacks are special cases of remote calls that execute as part of a single thread. A callback is issued in the context of a remote call. Any remote procedure defined as part of the same interface as the static callback function can call the callback function.
Handles cannot be used as parameters in callback functions. Because callbacks always execute in the context of a call, the binding handle used by the client to make the call to the server is also used as the binding handle from the server to the client.

Callbacks can nest to any depth.
hiflower 2003-12-15
  • 打赏
  • 举报
回复
回复人: qiume(杜克) ( ) 信誉:100 2003-12-12 17:33:00 得分:0


// TSocketConnection的SupportCallbacks 设为False即可,如:
SocketConnection1.SupportCallbacks := False;

----------------------------------------------------
杜克兄的办法确实解决了问题,那么有谁知道原因是什么?
猛禽 2003-12-15
  • 打赏
  • 举报
回复
怀疑是SocketConnection控件的问题,只是开了这个属性就会有一堆的问题
hiflower 2003-12-15
  • 打赏
  • 举报
回复
我把杜克兄提供的资料翻译了一部分:

说明:
callback 属性声明了一个静态的回调函数,此回调函数存在于分布式应用程序的客户端。回调函数为服务器执行客户端的代码提供了一个途径。
当服务器必须从客户端得到信息时,回调函数是很有用的。如果在 Windows 3.x 上支持服务器应用程序,则服务器能够调用 Windows 3.x 服务器上的一个远程过程来得到需要的信息。回调函数完成同样的目的。回调允许服务器在最初调用的上下文中查询信息。
回调是远程调用的特殊情况,它作为单独的线程执行。回调在一个远程调用的上下文中执行。如同静态回调函数,定义成同一接口一部分的任何远程过程都能够称为回调函数。
在回调函数中,不能用句柄作为参数。因为回调总是在一个调用的上下文中执行,客户端用来进行调用服务器的绑定句柄,也被用作从服务器到客户端的绑定句柄。
回调能嵌套任意次数。
==========================================
从中看不出有什么问题。
按理说,我的服务端其实并未开(就连 ScktSrvr.exe 也未运行)。
难道说,允许了 SocketConnection 的 Callback 机制,就会产生问题吗?
怪的是,它还与 ShowMessage, MessageBox 有关系啊!
猛禽 2003-12-15
  • 打赏
  • 举报
回复
SocketConnection的CALLBACK支持有问题,我从来都不开,除了这个问题以外,还有很多其它的问题。
pandengzhe 2003-12-12
  • 打赏
  • 举报
回复
我的没问题。。。up
hiflower 2003-12-12
  • 打赏
  • 举报
回复
我是 Win2000+D6
如果不手工关闭此程序,Windows 就不能关闭/注销了.
pandengzhe 2003-12-12
  • 打赏
  • 举报
回复
win2003+d7,没问题啊,不明白楼主意思。。。
pandengzhe 2003-12-12
  • 打赏
  • 举报
回复
xx+gz+up...

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧