Solved

Thread problem

Posted on 2004-09-25
8
355 Views
Last Modified: 2010-04-06
When I try to set:

Priority := tpNormal ;

get next error message:

"Thread error: The handle is invalid (6)"

constructor TGNThread.Create( AnimateMe : TgnClass );
begin
 Animated                 := AnimateMe;
 Priority                    := tpNormal     ; // here is my problem. If delete it all work fine !?!?!?
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;
 inherited Create ( False );
end;

0
Comment
Question by:ginsonic
  • 4
  • 2
  • 2
8 Comments
 
LVL 6

Accepted Solution

by:
vadim_ti earned 250 total points
ID: 12150412


constructor TGNThread.Create( AnimateMe : TgnClass );
begin
inherited Create ( true);
 Animated                 := AnimateMe;
 Priority                    := tpNormal     ; // here is my problem. If delete it all work fine !?!?!?
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;
 suspended := false;
end;
0
 
LVL 22

Assisted Solution

by:Ferruccio Accalai
Ferruccio Accalai earned 250 total points
ID: 12150453
vadim_ti is right....(he deserves the points)

Now just to explane it you can change the default Priority just when the Thread is already created otherwise the error is raised as there's no handle for the Thread, tyhat means that the System try to execute scheduled a non-handled Thread....

So you can also write your constructor as

constructor TGNThread.Create( AnimateMe : TgnClass );
begin
   Animated                 := AnimateMe;
   OnTerminate           := Animated.Fine;
   FreeOnTerminate     := True; //'til here the Thread handle isn't needed as these are just Object properties
   inherited Create ( true);
   Priority                    := tpNormal; //but this needs the Thread handle in process
   Resume; //Now let's resume it
end;

0
 
LVL 9

Author Comment

by:ginsonic
ID: 12153480
I split the points beacause the real solution was to call firat inherited Create(True);
Don't need to suspend or resume my thread. Just:

 Animated                 := AnimateMe;
 Priority                    := tpNormal     ;
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;
 suspended := false;

 What was interesting is that an old compiled exe what use inherited after ( wrongh way ) run perfect !?!? The new compiled return the error!?!?!?

Thanks for help!
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 9

Author Comment

by:ginsonic
ID: 12153483
Sorry , I wish to say:

 inherited Create ( true);
 Animated                 := AnimateMe;
 Priority                    := tpNormal     ;
 OnTerminate           := Animated.Fine;
 FreeOnTerminate     := True;

Copy problem :)
0
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12153573
with your contructor without

suspended := false

thread will not run (execute). you will successfully create it, but it will in suspended state

inherited Create(true)

will create it in suspended,
.Execute method will never called

so you need
suspended := false or calling Resume

to resume thread
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12155194
Look like resume solve all problems. Suspended make my VCL to not work for all my actions.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12155196
Thanks again for support!
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12155393
:)) That's why i've used resume in my example :)

F68 ;-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send message from delphi to whatsapp, is it possible? 3 1,445
error 1.1 400 Bad request idhttp delphi 18 87
Delphi...Split view - idea? 1 68
RESTRequest Parameter 4 30
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 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