TListView.BeginUpdate 防止提示显示在不相关的控件上

问题描述 投票:0回答:0

启用计时器后,按钮上的提示将不会显示(例外:如果按钮已显示其提示 - 当计时器被禁用时 - 提示仍会显示;但这仅适用于最后一个按钮显示它的提示)

由于定时器的代码不以任何方式访问按钮,我不理解这种行为。谁能解释发生了什么以及如何解决这个问题?

(如果这有帮助:这是一个 MRE,在实际代码中,列表视图通过队列以 250 毫秒的间隔从线程更新)

var
  DoOnce: Boolean = False;

procedure TForm1.Button2Click(Sender: TObject);

  procedure Setup;
  var
    I: Integer;
  begin
    // problem occurs even when NOT created by code
    // this is just to make reproduction easier
    for I := 1 to 3 do
      with TButton.Create(Form1) do begin
        Parent := Form1;
        Hint := IntToStr(I);
        ShowHint := True;
        Top := 8;
        Left := 8 + I * (Width + 8);
      end;
    ListView1.ViewStyle := vsReport;
  end;

begin
  if not DoOnce then begin
    DoOnce := True;
    Setup;
  end;
  with Timer1 do begin
    Interval := 250;
    Enabled := not Enabled;
    Form1.Caption := BoolToStr(Enabled, True);
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  with Form1.ListView1.Items do begin
    BeginUpdate;
    Sleep(1);
    EndUpdate;
  end;
end;
delphi vcl hint tlistview
© www.soinside.com 2019 - 2024. All rights reserved.