Delphi Thread Class DIY (pass the class pointer as a parameter, you can execute the method in the class)

Source: Internet
Author: User
Tags thread class

Delphi encapsulates a very powerful threading class TThread,

We also make a simple threading class by ourselves

First type of a class

[Delphi]View PlainCopy
    1. type  
    2.    twwthread = class  
    3.      constructor create; overload;  
    4.      DESTRUCTOR DESTROY; OVERRIDE;  
    5.   PRIVATE  
    6.     m_hthread: thandle;     //thread   
    7.     m_threadid : tthreadid;  
    8.   public  
    9.      procedure execute;  
    10.    END;  

[Delphi]View PlainCopy
  1. function Wwthreadproc (thread:twwthread): Integer;
  2. Begin
  3. Thread. Execute (); //  
  4. End
  5. Constructor Twwthread.  Create;
  6. Begin
  7. M_hthread: = CreateThread (nil, 0, @wwThreadProc, Pointer (self), 0, M_threadid); {The focus here is on the fourth parameter, passing the class pointer as a parameter, so you can execute the method inside the class}
  8. End
  9. destructor Twwthread.  Destroy;
  10. Begin
  11. inherited;
  12. End
  13. Procedure Twwthread.  Execute;
  14. Begin
  15. //write the code here
  16. End


To declare:

[Delphi]View PlainCopy
    1. Var
    2. Mythread:twwthread;

Start ~

[Delphi]View PlainCopy
      1. MyThread: = Twwthread.  Create;

http://blog.csdn.net/warrially/article/details/7887700

Delphi Thread Class DIY (pass the class pointer as a parameter, you can execute the method in the class)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.