CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

请问我这段关于线程的代码有什么问题?

楼主wealsh(工作狂人)2006-05-04 15:38:42 在 Delphi / VCL组件开发及应用 提问

 
    type  
        Myzhiling   =   record  
          command:   Integer;  
      end;  
   
        ClientInfo   =   record  
            PcName:string[5];//名称  
            passwd:string[20];//密码  
            command:string[5];//指令  
            Ver:string[2];         //版本  
            Text:string;     //附加信息  
          end;    
   
      TMyThread   =   class(TThread)  
      private  
          F_info:ClientInfo;  
          F_Athread:   TIdPeerThread;  
      protected  
          procedure   DoTerminate;   override;  
      public  
          constructor   Create(C_info:ClientInfo;   const   C_Athread:   TIdPeerThread);  
          destructor   Destroy;   override;  
          procedure   Execute;   override;  
      end;  
   
  implementation  
   
  uses   main;  
   
  {   TCheckThread   }  
   
  constructor   TMythread.Create(C_info:ClientInfo;   const   C_Athread:   TIdPeerThread);  
  begin  
      inherited   Create(False);  
      FreeOnTerminate   :=   True;  
   
      F_info:=C_info;  
      F_Athread   :=   C_Athread;  
  end;  
   
  destructor   Tmythread.Destroy;  
  begin  
      inherited   Destroy;  
  end;  
   
  procedure   TMythread.DoTerminate;  
  begin  
      inherited   DoTerminate;  
  end;  
   
  procedure   TMythread.Execute;  
  begin  
    with   Form1   do  
      begin    
        EnterCriticalSection(cs);  
          if   F_info.command='ADD'then  
            begin  
                form1.listview1.items.add................    
            end;    
        LeaveCriticalSection(cs);  
    Terminate;  
    end;  
   
   
   
  //=========================  
   
  procedure   TForm1.IdTCPServer1Execute(AThread:   TIdPeerThread);  
  var  
      C_info:ClientInfo;  
  begin  
  //     if   (not   AThread.Terminated)   and   (AThread.Connection.Connected=True)   then  
        begin  
          AThread.Connection.ReadBuffer(C_info,SizeOf(C_info));  
          TMyThread.Create(C_info,AThread);  
        end;  
  end; 问题点数:50、回复次数:2Top

1 楼qlwuu(沉睡火山)回复于 2006-05-04 16:10:59 得分 25

不要在主线程以外的地方访问vcl控件。Top

2 楼fanshousu()回复于 2006-05-05 10:46:58 得分 25

在线程中访问VCL控件的时候,请使用Synchronize  
  按照你的上面写法,程序中Form1将会出现停止状态,这是由于Form1将不能其他的访问Top

相关问题

关键词

得分解答快速导航

  • 帖主:wealsh
  • qlwuu
  • fanshousu

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo