为什么我的程序,要到数据映射提示框出现后ProgressBar才开始有变化?
加上Timer1.Enabled := False;这句直接就没有反应,谁能给我讲解一下到底怎么回事吗?
procedure TForm1.Button1Click(Sender: TObject);
var
  I : Integer;
begin
  if edit1.Text <> '' then
  begin
    if Application.MessageBox('确认要将此数据库对应?','提示',MB_IConInformation + MB_OKCancel) = IdOk then
    begin
      Timer1.Enabled := True;
      //GetTime := GetTickCount;      //DataModule1.ADoConnection1.Connected := False;
      //DataModule1.ADOConnection1.ConnectionString := ConnStr;
      //DataModule1.ADOConnection1.Connected := True;      //SelectData;      //DataModule1.AdoDataSet1.Close;      //ExecuteTime := GetTickCount - GetTime;      //Timer1.Enabled := False;
      Application.MessageBox('数据映射完毕!','提示',MB_IConInformation + MB_OK);
      //edtText.SetFocus;
    end
    else
      Exit;
  end
  else
  begin
    Application.MessageBox('请选择文件!','提示',MB_IConInformation + MB_OK);
    //edtData.SetFocus;
  end;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var
  I : Integer;
begin
  for I := 0 to 100 do
  begin
    ProgressBar1.StepIt;
    ProgressBar1.Position := ProgressBar1.Position + 1;
    ProgressBar1.Update;
  end;
end;

解决方案 »

  1.   

    Timer1设置的时长,还有就是需要设置Application.ProcessMessages;
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I : Integer;
    begin
      for I := 0 to 100 do
      begin
        ProgressBar1.StepIt;
        Application.ProcessMessages;
      end;
    end;
      

  2.   

    把你timer中的循环直接做成一个过程,直接调用不就完了。
      

  3.   

    dataset 的 executeoption 设置为eoAsyncFetchNonBlocking 同时使用Application.ProcessMessages 效果应该会更好!
      

  4.   

    SelectData是一个过程调用吧?如果是,SelectData过程中应该有循环语句吧?如果是,那楼主应该是在循环语句中修改进度条的状态,并执行Application.ProcessMessages语句。另外,不要用Timer事件。