unit U_FormInitThread;

interface
uses
  Classes, SysUtils, Forms,U_WindowFormdesign,Messages,Data.DB,Data.Win.ADODB;
type
  TFormInitThread = class(TThread)
  private
    fWindowDesign: TWindowFormdesign; // 替换为你的数据模块类型
    fForm:Tform;
    fFormId:integer;
    fADOTmp: TADOQuery;
    fADOQCmd: TADOQuery;
    fWhichFun:String;
    procedure LoadData;
  protected
    procedure Execute; override;
  public
    constructor Create( mWindowDesign: TWindowFormdesign;mForm: Tform; mFormId: integer; ADOTmp: TADOQuery; ADOQCmd: TADOQuery;mWhichFun:String);
  end;

implementation

constructor TFormInitThread.Create(mWindowDesign: TWindowFormdesign;mForm: Tform; mFormId: integer; ADOTmp: TADOQuery; ADOQCmd: TADOQuery;mWhichFun:String);
begin
  inherited Create(False);
   fWindowDesign := mWindowDesign;
   fForm:= mForm ;
   fFormId:=mFormId;
   fADOTmp:=  ADOTmp ;
   fADOQCmd:=  ADOQCmd ;
   fWhichFun:= mWhichFun ;
   FreeOnTerminate := True; // 线程终止时自动释放
end;

procedure TFormInitThread.Execute;
begin
  // 在这里执行耗时的数据加载操作
    Synchronize(LoadData); // 使用 Synchronize 方法确保在主线程中更新 UI
  //LoadData();
end;
procedure TFormInitThread.LoadData;
begin
  // 这里是实际加载数据的代码
  // 假设你有一个方法叫 LoadDataFromDatabase 在数据模块中
  if fWhichFun='' then
    fWindowDesign.FormStyleInit1(fForm, fFormId, fADOTmp, fADOQCmd, '', '')
  else
    fWindowDesign.FormStyleInit(fForm, fFormId, fADOTmp, fADOQCmd, '', '');

     // showMessage('44');
 // for I := 0 to 10000000000 do
 // begin
 //  if I=1000000000 then
 //  begin
   //  application.MessageBox(pchar('444'),'',0);
 //  end;
 //end;

  // 如果需要更新 UI，可以在这里做，因为 Synchronize 保证了它在主线程中执行
  // 例如：YourForm.YourControl.Caption := 'Data Loaded';
  // 注意：确保 YourForm 和 YourControl 在此上下文中是有效的，或者通过其他方式传递引用
end;
end.
