delphi的TThread.CreateAnonymousThread导致界面卡死

delphi的TThread.CreateAnonymousThread调用tabcontrol页的未显示的tabsheet中的CheckListBox控件导致导致主界面卡死,具体情况不明白。CheckListBox的内容为空触发,有内容一切正常。

procedure TForm1.Button1Click(Sender: TObject);
begin
 TThread.CreateAnonymousThread
  (
    procedure ()
    var
      i,iCurrentProIndex:Integer;
    begin
      if CheckListBox1.Items.Count<=0 then
      begin
        //showMessage('fuck');
      end;
      sleep(10000)
    end).start;
end;
正常情况下,调用sleep主线程不会卡死的。实际运行结果和主线程执行sleep一个效果。


object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 300
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object PageControl1: TPageControl
    Left = 0
    Top = 0
    Width = 635
    Height = 300
    ActivePage = TabSheet1
    Align = alClient
    TabOrder = 0
    ExplicitLeft = 8
    ExplicitTop = 8
    ExplicitWidth = 619
    ExplicitHeight = 217
    object TabSheet1: TTabSheet
      Caption = 'TabSheet1'
      ExplicitWidth = 281
      ExplicitHeight = 165
      object Button1: TButton
        Left = 44
        Top = 228
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 0
        OnClick = Button1Click
      end
    end
    object TabSheet2: TTabSheet
      Caption = 'TabSheet2'
      ImageIndex = 1
      ExplicitWidth = 285
      ExplicitHeight = 169
      object CheckListBox1: TCheckListBox
        Left = 456
        Top = 27
        Width = 121
        Height = 97
        Color = 4227200
        ImeName = #20013#25991' - QQ'#25340#38899#36755#20837#27861
        ItemHeight = 13
        TabOrder = 0
      end
    end
  end
end

你可能感兴趣的:(bug,Delphi)