delphi等待动画
delphi等待动画
首先要在网上下载等待的GIF文件。
unit wait; /// <author>cxg 2022-8-12</author> interface uses Vcl.Imaging.GIFImg, System.SysUtils, Vcl.Graphics, Vcl.Controls, forms, Vcl.ExtCtrls, Vcl.StdCtrls; function playWait(own: TForm): TPanel; procedure stopWait(pnl: TPanel); implementation function playWait(own: TForm): TPanel; begin var pnl: TPanel := TPanel.Create(own); pnl.BevelOuter := bvNone; pnl.Parent := own; pnl.AutoSize := True; pnl.Left := Screen.Width div 2; pnl.Top := Screen.Height div 2 - 150; pnl.Show; var img: TImage := TImage.Create(pnl); img.Parent := pnl; img.Stretch := true; img.AutoSize := True; img.Picture.LoadFromFile(ExtractFilePath(Application.ExeName) + '1.gif'); TGIFImage(img.Picture.Graphic).Animate := True; Result := pnl; end; procedure stopWait(pnl: TPanel); begin FreeAndNil(pnl); end; end.
procedure Tfgoods.chaxunExecute(Sender: TObject); begin var finished: Boolean := False; ADOQuery1.Close; ADOQuery1.DisableControls; var pnl: TPanel := playwait(self); TThread.CreateAnonymousThread( procedure begin CoInitialize(nil); ADOQuery1.Close; ADOQuery1.SQL.Clear; var sql: string; var v: string; if edtId.Text <> '' then begin sql := 'select * from t_goods where goodsid = :goodsid'; ADOQuery1.SQL.Add(sql); v := edtId.Text; ADOQuery1.Parameters.ParamValues['goodsid'] := v; end else if edtPy.Text <> '' then begin sql := 'select * from t_goods where isnull(py,'''') like :py'; ADOQuery1.SQL.Add(sql); v := '%' + edtPy.Text + '%'; ADOQuery1.Parameters.ParamValues['py'] := v; end else if edtName.Text <> '' then begin sql := 'select * from t_goods where isnull(goodsname,'''') like :goodsname'; ADOQuery1.SQL.Add(sql); v := '%' + edtName.Text + '%'; ADOQuery1.Parameters.ParamValues['goodsname'] := v; end else if edtBarcode.Text <> '' then begin sql := 'select * from t_goods where isnull(barcode,'''') = :barcode'; ADOQuery1.SQL.Add(sql); v := edtBarcode.Text; ADOQuery1.Parameters.ParamValues['edtBarcode'] := v; end else begin sql := 'select * from t_goods'; ADOQuery1.SQL.Add(sql); end; ADOQuery1.Open; finished := true; //thread execute finished CoUninitialize; end).Start; while True do //wait for thread execute finished begin if finished then begin ADOQuery1.EnableControls; stopWait(pnl); Break; end; Application.ProcessMessages; TThread.Sleep(1); end; end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/16582176.html