Solved

Threading in delphi

Posted on 2011-03-03
6
489 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Expert Comment

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article will show, step by step, how to integrate R code into a R Sweave document
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

705 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

18 Experts available now in Live!

Get 1:1 Help Now