这是 MIDAS 三层中的客户端应用程序。
点 Button1,再点 Button2,或先 Button2,再 Button1 后,Windows 关闭/注销时,此程序不能终止。
服务端程序启动或不启动都无所谓,结果都一样。高手快来帮忙啊。unit Unit1;interfaceuses
  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.

解决方案 »

  1.   

    win2003+d7,没问题啊,不明白楼主意思
      

  2.   

    我是 Win2000+D6
    如果不手工关闭此程序,Windows 就不能关闭/注销了.
      

  3.   

    回复人: qiume(杜克) ( ) 信誉:100  2003-12-12 17:33:00  得分:0 
     
     
      // TSocketConnection的SupportCallbacks 设为False即可,如:
      SocketConnection1.SupportCallbacks := False;
      
    ---------------------------------------------------- 
    杜克兄的办法确实解决了问题,那么有谁知道原因是什么?
      

  4.   

    //以下是我在WINDOWS的SDK里找的:
    callback[callback [ , function-attr-list] ] type-specifier [ptr-declarator] function-name(
    [ [parameter-attribute-list] ] type-specifier [declarator]
    , ...
    );function-attr-listSpecifies 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-specifierSpecifies a base_type, struct, union, enum type, or type identifier. An optional storage specification can precede type-specifier.ptr-declaratorSpecifies 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-nameSpecifies the name of the remote procedure.parameter-attribute-listSpecifies zero or more directional attributes, field attributes, usage attributes, and pointer attributes appropriate for the specified parameter type. Separate multiple attributes with commas.declaratorSpecifies 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);
    ResThe 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.
      

  5.   

    SocketConnection的CALLBACK支持有问题,我从来都不开,除了这个问题以外,还有很多其它的问题。
      

  6.   

    我把杜克兄提供的资料翻译了一部分:说明:
        callback 属性声明了一个静态的回调函数,此回调函数存在于分布式应用程序的客户端。回调函数为服务器执行客户端的代码提供了一个途径。
        当服务器必须从客户端得到信息时,回调函数是很有用的。如果在 Windows 3.x 上支持服务器应用程序,则服务器能够调用 Windows 3.x 服务器上的一个远程过程来得到需要的信息。回调函数完成同样的目的。回调允许服务器在最初调用的上下文中查询信息。
        回调是远程调用的特殊情况,它作为单独的线程执行。回调在一个远程调用的上下文中执行。如同静态回调函数,定义成同一接口一部分的任何远程过程都能够称为回调函数。
        在回调函数中,不能用句柄作为参数。因为回调总是在一个调用的上下文中执行,客户端用来进行调用服务器的绑定句柄,也被用作从服务器到客户端的绑定句柄。
        回调能嵌套任意次数。
    ==========================================
    从中看不出有什么问题。
    按理说,我的服务端其实并未开(就连 ScktSrvr.exe 也未运行)。
    难道说,允许了 SocketConnection 的 Callback 机制,就会产生问题吗?
    怪的是,它还与 ShowMessage, MessageBox 有关系啊!
      

  7.   

    怀疑是SocketConnection控件的问题,只是开了这个属性就会有一堆的问题
      

  8.   

    看了看 VCL 源码,当SupportCallbacks 为 True 时,在 Open 时是建立一个线程处理的,大概是这个线程有问题,不想再深入研究了,不开这个属性得了。
      

  9.   

    一般是用不着,我从来都是一放上SOCKETCONNECTION就把它设置为FALSE
      

  10.   

    SocketConnection 在内部的确使用了消息循环。不管 SupportCallbacks 为何值,在 Open 时都是会建立一个线程来处理 Socket。 不过,出现这种问题,的确很奇怪。