| View previous topic :: View next topic |
| Author |
Message |
GuM Expert Cheater
Reputation: 0
Joined: 17 Jan 2007 Posts: 185 Location: The Netherlands
|
Posted: Wed Dec 26, 2007 10:56 am Post subject: [Delphi] Multi-Threading |
|
|
Could anyone explain to me how I can create threads in Delphi? I've looked at some tutorials but I still don't understand it. I want to make a program that sends messages to a Memobox, but doesn't lock up while doing that.
Thanks.
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Wed Dec 26, 2007 12:34 pm Post subject: |
|
|
Look at this code:
By Google Lab
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 474
Joined: 09 May 2003 Posts: 25957 Location: The netherlands
|
Posted: Wed Dec 26, 2007 1:29 pm Post subject: |
|
|
you could of course do the windows api method:
define a function like:
function mythread(parmeter: pointer); stdcall;
begin
//your threadcode
end;
...
...
var tid: dword;
begin
createthread(nil,0, @mythread, nil, 0, tid);
..
..
OR use a object oriented method using the TThread class (my prefered method)
type tmythread=class(tthread)
public
procedure execute; override;
end;
procedure tmythread.execute;
begin
//do your thread stuff here
end;
...
tmythread.create(false);
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Wed Dec 26, 2007 2:15 pm Post subject: |
|
|
| Using the TThread class is the easiest way because you can control your thread very easily without using Win32 APIs.
|
|
| Back to top |
|
 |
GuM Expert Cheater
Reputation: 0
Joined: 17 Jan 2007 Posts: 185 Location: The Netherlands
|
Posted: Thu Dec 27, 2007 9:46 am Post subject: |
|
|
| Okey, but how do I run the Thread? When I do "TMyThread.Create(False);" it gives me an error. "TMyThread.Resume;" also gives me an error.
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Thu Dec 27, 2007 9:59 am Post subject: |
|
|
| TMyThread.execute;
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Thu Dec 27, 2007 12:10 pm Post subject: |
|
|
Post your source. TMyThread.Create(False) should work. If your thread is in another source file, you should add that source file to the implementation uses list of your main program.
What does the error say? Is it a compiler error or runtime error?
|
|
| Back to top |
|
 |
GuM Expert Cheater
Reputation: 0
Joined: 17 Jan 2007 Posts: 185 Location: The Netherlands
|
Posted: Thu Dec 27, 2007 2:32 pm Post subject: |
|
|
Oh nvm. It already works.
Thanks
|
|
| Back to top |
|
 |
|