Solved

Threading in delphi

Posted on 2011-03-03
6
490 Views
Last Modified: 2012-05-11
Hello
Help me please

How can i make that application do anything with multi-threads.
Example : how can i make that program runs a work with 10 or more threads?

thanks
0
Comment
Question by:helyonprime96
6 Comments
 
LVL 14

Accepted Solution

by:
systan earned 500 total points
ID: 35029416
>>do anything with multi-threads.
?
I'm not sure the way you wanted, but you can look this project;
 multi-threading-progressbar.zip
and this one;
 delphi-thread-gui2.zip
and this database project too;
 adothreading.zip
0
 
LVL 3

Expert Comment

by:Freddy1990
ID: 35029445
The easiest way is sublassing the TThread class.

uses Classes;
type
  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  public
    constructor Create;
    destructor Destroy; override;
  end;
...
procedure TMyThread.Create;
begin
  inherited Create(False);
  FreeOnTerminate := True;
end;

This example would start the thread instantly after creation and free it automatically on termination. You just put the code you want to execute in the Execute method.

If you want to interact with the main thread, you need to synchronize calls by adding a method to the thread without result or parameters and calling Synchronize on it, like Synchronize(Method);
0
 

Author Closing Comment

by:helyonprime96
ID: 35029477
thanks a lot!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Freddy1990
ID: 35029500
Your welcome?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 35030312
wow, systan, you have found some really bad samples in threading
i didn't know samples like that existed

worst idea is to use (or reference) visual vcl objects from within a thread

never ever do that ... that's asking for trouble

helyonprime96,
do not ever (unless you really want trouble) put things like
fLabel: TLabel, fProgressbar: TProgressbar
inside a TThread class definition

you should have accepted Freddy1990's solution
as systan inidicated, she still needs to read a lot about threading ...

man, man, man, this is unbelievable ... another one will bite the dust when it comes to threading
0
 
LVL 14

Expert Comment

by:systan
ID: 35039230
the samples are from Delphi.About.com,
even you sometimes refereed that link, maybe.

there are many ways to drink the beer without getting drunk.


Sorry, if I am a bad expert, just as your article says? but I'm modest.


Now about your article here;
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/A_239-Displaying-progress-in-the-main-form-from-a-thread-in-Delphi.html


Will you correct the code of AdoThreading from delphi.about.com?
I know it's so easy for you, so lets see what is the difference and result of the code when it changes in your hands.
If this discussion is pointless then let it be.
Here's the code;
http://filedb.experts-exchange.com/incoming/2011/03_w10/416071/adothreading.zip
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now