Solved

Thread problem

Posted on 2004-09-25
8
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi inherited method 6 80
enhance the following code 3 42
shape, triangle, dbctrlgrid 3 32
Problem working with dynamic array - help 2 35
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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