Results 1 to 1 of 1
  1. #1
    radiaku
    radiaku is offline
    Guest
    Join Date
    2014 Sep
    Posts
    2
    Thanks Thanks Given 
    2
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0

    Simple Thread Worker for delphi ( same as backgroundworker in C# )

    Hello there. I starting delphi ( free pascal ), I have confused how to doing background worker in delphi and this what I found this solution.

    This for unfreezing UI when executing long task.

    Add this before after type

    PHP Code:
    // =========== WORKER CLASS
    TMyWorkerThread = class(TThread)
     protected
       
    // the main body of the thread
       
    procedure Executeoverride;
     
    end;
    // =========== WORKER CLASS 

    then add this after implementation

    PHP Code:
    procedure TMyWorkerThread.Execute;


    var
    integer;
    begin
      i 
    := 0;
      while 
    100 do
      
    begin
        
    // play beep sound
        
    Form1.Label1.Caption := IntToStr(i);
        
    sleep(100); //refreshing cpu -- around 16 miliseconds
        // process pending messages might be in message queue
        
    i:= +1;
        
    //Application.ProcessMessages;

      
    end;
      
    //Here we do work
       //showmessage('aaaaaaaaaa');
      //When we exit the procedure, the thread ends.
      //So we don't exit until we're done.
    end


    And called it when button click or else

    PHP Code:
    TMyWorkerThread.Create(false); 

    FULL CODE

    FULLCODE


Similar Threads

  1. Replies: 8
    Last Post: 2015-11-03, 04:46 AM
  2. Replies: 12
    Last Post: 2013-04-20, 03:34 PM
  3. [Delphi] Creating a Simple Game Trainer
    By Dwar in forum Delphi
    Replies: 21
    Last Post: 2012-07-24, 02:38 PM
  4. [Delphi] Simple Dll Injection
    By Dwar in forum Delphi
    Replies: 1
    Last Post: 2012-03-29, 04:14 PM
  5. [Delphi] Delphi Training Video
    By Dwar in forum Programming Tutorials
    Replies: 0
    Last Post: 2010-11-29, 04:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •