真是苦闷..这是个老问题,在很多论坛、讨论上出现过无数次讨论。 不过任我怎么试 还是没找到完好的解决办法.
可能是本人太过cn, 真希望有高人可以指点迷津啊. 说来简单,我的目的只是在执行数据库查询的时候,TAnimate上查找的图标能不断地动 让人感觉程序没有死!
 unit Form1 
  ....
  ....
 procedure  TForm1.DatabaseExecute;
 begin  
   MessageForm:=TMessageform.Create(self);
   MessageForm.Message_Pl.Caption:= '正在统计,请稍候...';
   MessageForm.Showmodal;              
   MessageForm.Update;                 
   Application.ProcessMessages ;
     DoSearching()..       //执行数据库的查询操作,需时20多秒,同时cpu上得很快 60% 70左右
   MessageForm.close;
 end;// 这个时候 MessageForm上的TAnimate上的aviFindFolder图标是不断的动的!
   只不过 Showmodal了,下面的DoSearchaning就不会执行。 
   但是一旦改成 MessageForm.Show的话  TAnimate上的动画就一动不动了!但是数据库的查询倒是能正常出来.就是动画不动看了一些论坛上似是而非的资料 ,跟着于是傻傻地理所当然想到了 多线程! 这真是架刀子上架,线程知识储备不多!
还是上把于是在Form1的开头,定义了一个公用函数 procedure SearchingMessage ;
begin
  MessageForm:=TMessageform.Create(Application);
  MessageForm.Message_Pl.Caption:= '正在统计,请稍候...';
  MessageForm.ShowModal;
  MessageForm.Update;
  Application.ProcessMessages ;
end;同时修改了一下 procedure  TForm1.DatabaseExecute;
 begin 
   hThread:=CreateThread(nil,0,@SearchingMessage,nil,0,ThreadID);  //创建了一个线程
   if hThread=0 then Messagebox(Handle,'Didn’t CreateaThread',nil,MB_OK);
   DoSearching()..       end;
 结果是,连那个等待的窗体都不出现了! 只是在数据出来那一刹那 兄弟我耳目清明才看得到一丝扶风掠影,它就这么一闪而过了 
 我想肯定是新线程打开窗体之后与原主线程之间的关系没调好 
 可是遍寻网上、坛坛,中文的英文的 都没有大虾给给出点点提示 我那是闷啊!

解决方案 »

  1.   

    我的MessageUnit 单元也简单,其中 Avi的CommonAvi值设为 aviFindFolderunit MessageUnit;
    interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,ComCtrls,   ExtCtrls ;type
      TMessageForm = class(TForm)
        Message_Pl: TPanel;
        Avi: TAnimate;
        procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);
        procedure   FormCreate(Sender:   TObject);
        procedure   FormShow(Sender:   TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;implementation{$R *.dfm}{ TMessageForm }procedure TMessageForm.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Screen.Cursor:=crDefault;
      if Avi.Active then Avi.Active:=False;
    end;procedure TMessageForm.FormCreate(Sender: TObject);
    begin
      self.Avi.Active:=True;
    end;procedure TMessageForm.FormShow(Sender: TObject);
    begin
    //  Screen.Cursor:=crSQLWait;
      self.Avi.Active:=True;
    end;end.
      

  2.   

    unit WaitDialog;
    //xiedewei 20101010
    interfaceuses
      Windows, Controls, Forms, Classes, ComCtrls, StdCtrls, Dialogs, SysUtils,
      Messages;type
      TWaitDlg = class(TForm)
        lblPrompt: TLabel;
        Animate: TAnimate;
        procedure FormCreate(Sender: TObject);
      private
        procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
      public
        procedure Show(Style: Integer);
        procedure Update(Msg: string); reintroduce;
        procedure Close;
      end;procedure OpenWaitWnd(Msg: string; Style: Integer = 4);
    procedure UpdateWaitWnd(Msg: string);
    procedure CloseWaitWnd;implementation{$R *.DFM}var
      theWaitWindow: TWaitDlg = nil;procedure OpenWaitWnd(Msg: string; Style: Integer = 4); export;
    begin
      if not Assigned(theWaitWindow) then
        theWaitWindow := TWaitDlg.Create(nil);
      theWaitWindow.Show(Style);
      theWaitWindow.Update(Msg);
    end;procedure UpdateWaitWnd(msg: string); export;
    begin
      if Assigned(theWaitWindow) then
        theWaitWindow.Update(Msg);
    end;procedure CloseWaitWnd; export;
    begin
      if Assigned(theWaitWindow) then
        theWaitWindow.Close;
    end;{ TWaitDlg }procedure TWaitDlg.Show(Style: Integer);
    begin
      Animate.CommonAVI := TCommonAVI(Style);
      Animate.Active := True;
      SetWindowPos(Handle, HWND_TOP, (Screen.Width - Width) shr 1,
        (Screen.Height - Height shl 1) shr 1, 0, 0, SWP_SHOWWINDOW or SWP_NOACTIVATE or SWP_NOSIZE);
    end;procedure TWaitDlg.Update(Msg: string);
    begin
      lblPrompt.Caption := Msg;
      inherited Update;
    end;procedure TWaitDlg.Close;
    begin
      ShowWindow(Handle, SW_HIDE);
      Animate.Active := False;
    end;procedure TWaitDlg.FormCreate(Sender: TObject);
    begin
      AlphaBlend := True;
      BorderStyle := bsToolWindow;
      ShowWindow(Animate.Handle, SW_SHOWNORMAL);
    end;procedure TWaitDlg.WMNCHitTest(var Message: TWMNCHitTest);
    begin
      Message.Result := HTTRANSPARENT;
    end;initializationfinalization
      if Assigned(theWaitWindow) then
        FreeAndNil(theWaitWindow);end.
    使用方法:
    uses WaitDialog;OpenWaitWnd('正在统计,请稍候...');
    DoSearching().. //执行数据库的查询操作,需时20多秒,同时cpu上得很快 60% 70左右
    CloseWaitWnd;