Non-visual compnent in a TThread descendent

Non-visual compnent in a TThread descendent

Post by Larry Matu » Fri, 22 Jul 2005 01:33:00


Is it possible to use a non-visual component in a TThread descendent? If
so, what do you pass into the constructor, which is expecing a TComponent
descendent, and not a TThread descendent?

-- Larry Maturo
 
 
 

Non-visual compnent in a TThread descendent

Post by Leone » Fri, 22 Jul 2005 01:35:05


nil?

--
Leonel

 
 
 

Non-visual compnent in a TThread descendent

Post by Wayne Nidd » Fri, 22 Jul 2005 01:59:18


Just pass nil. There is no requirement that a TComponent *actually* be owned
by another TComponent. In this case, it is your responsibility to free that
component when the thread object is destroyed.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.yqcomputer.com/
"Democracy, without the guarantee of liberty, is merely a method of
selecting tyrants." - Alan Nitikman
 
 
 

Non-visual compnent in a TThread descendent

Post by Larry Matu » Fri, 22 Jul 2005 02:00:53

Hi Leonel,

Cool, that compiles. I notice that code in the Constructor does not
actually used this variable, and the code in the Constructor for TComponent,
it checks and dosen't use the parameter if its nil, so it looks like the
parameter is optional, and nil should work just fine.

Thank you very much.

-- Larry
 
 
 

Non-visual compnent in a TThread descendent

Post by Craig Stun » Fri, 22 Jul 2005 02:01:00


It depends on whether the component is thread-safe. Some, like IBX
datasets, are. Some are not.


Either nil or a component created in the same thread. AFAIK there's
nothing threading-unsafe in the Ownership mechanism. But I generally
use nil when I create components in code, unless I have a really good
reason to use Ownership.

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://www.yqcomputer.com/
Useful articles about InterBase development:
http://www.yqcomputer.com/
 
 
 

Non-visual compnent in a TThread descendent

Post by Craig Stun » Fri, 22 Jul 2005 03:04:35


AOwner determines the lifetime management of the component. If nil,
you must free it yourself. If non-nil, the Owner will free it when the
Owner is freed.

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://www.yqcomputer.com/
Everything You Need to Know About InterBase Character Sets:
http://www.yqcomputer.com/
 
 
 

Non-visual compnent in a TThread descendent

Post by Larry Matu » Fri, 22 Jul 2005 07:44:40

Thank you all for the suggestions. I'll use nil, and make sure I free it
myself. The
help is much appreciated.

-- Larry Maturo