zoukankan      html  css  js  c++  java
  • 【转】利用线程更新ListView (2014-09-28 08:25:20)

    http://blog.sina.com.cn/s/blog_44fa172f0102v2x0.html

    procedure TForm5.Button3Click(Sender: TObject);
    begin
      TThread.CreateAnonymousThread(procedure ()
      var
        I: Integer;
        Total: Integer;
      begin
        Total := 0;
        for I := 1 to MaxValue do
        begin
          if (I * 10 mod MaxValue) = 0 then
            TThread.Synchronize (TThread.CurrentThread,
              procedure ()
              begin
                ListView1.Items.Add.Text := 'Th: ' + I.ToString;
              end);

          if IsPrime (I) then
            Inc (Total);
        end;

        TThread.Synchronize (TThread.CurrentThread,
          procedure ()
          begin
            ListView1.Items.Add.Text := 'Thread: ' + Total.ToString;
            NotifyComplete;
          end);
      end).Start;
    end;

    笔者测试,xe6可以编译通过,xe7无法编译通过。
        TThread.CreateAnonymousThread(
          procedure()
          begin
            TThread.Synchronize(TThread.CurrentThread,
              procedure()
              begin
                button1.Text := 'aaaa';
              end);
          end).Start;

    10.8放假回来,xe7又可以编译上面的代码了!
    10.10.反复的修改代码,发现无法编译的代码是在Synchronize中引用了局部循环变量,如果再声明一个临时变量来取代这个循环变量,就可以编译通过。

    原文

    http://www.dfwlt.com/forum.php?mod=viewthread&tid=711

  • 相关阅读:
    C# 从服务器下载文件
    不能使用联机NuGet 程序包
    NPOI之Excel——合并单元格、设置样式、输入公式
    jquery hover事件中 fadeIn和fadeOut 效果不能及时停止
    UVA 10519 !! Really Strange !!
    UVA 10359 Tiling
    UVA 10940 Throwing cards away II
    UVA 10079 Pizze Cutting
    UVA 763 Fibinary Numbers
    UVA 10229 Modular Fibonacci
  • 原文地址:https://www.cnblogs.com/westsoft/p/8458775.html
Copyright © 2011-2022 走看看