Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 4719|回复: 3

lazarus怎样线程同步,按delphi的写法编译不通过!!!!

[复制链接]

该用户从未签到

发表于 2010-1-7 10:38:15 | 显示全部楼层 |阅读模式
lazarus怎样线程同步,按delphi的写法编译不通过!!!!

错误提示: unit_read_thread.pas(28,25) Error: Incompatible type for arg no. 1: Got "untyped", expected "<procedure variable type of procedure of object;Register>"
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2010-1-7 10:45:30 | 显示全部楼层
自己来解答吧
贴一些代码

  Type
    TMyThread = class(TThread)
    private
      fStatusText : string;
      procedure ShowStatus;
    protected
      procedure Execute; override;
    public
      Constructor Create(CreateSuspended : boolean);
    end;

  constructor TMyThread.Create(CreateSuspended : boolean);
  begin
    FreeOnTerminate := True;
    inherited Create(CreateSuspended);
  end;

  procedure TMyThread.ShowStatus;
  // this method is executed by the mainthread and can therefore access all GUI elements.
  begin
    Form1.Caption := fStatusText;
  end;

  procedure TMyThread.Execute;
  var
    newStatus : string;
  begin
    fStatusText := 'TMyThread Starting...';
    Synchronize(@Showstatus);
    fStatusText := 'TMyThread Running...';
    while (not Terminated) and ([any condition required]) do
      begin
        ...
        [here goes the code of the main thread loop]
        ...
        if NewStatus <> fStatusText then
          begin
            fStatusText := newStatus;
            Synchronize(@Showstatus);
          end;
      end;
  end;

其实就差一个  @
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-1-8 11:00:28 | 显示全部楼层
呵呵,自己的问题自己解答。
学习了,谢谢lz分享。
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-3-4 09:58:21 | 显示全部楼层
赞一个。有好多楼主一句我已经自己解决就闪人了,还是贴出解决方法好
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-7-2 01:20 , Processed in 0.027190 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表