Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using TADOCommand 1

Status
Not open for further replies.

ByzantianX

Programmer
Dec 18, 2000
103
0
0
I would like to use an object variable in the code that is an instance of TADOCommand object, but I don't want to use TADOCommand component in design mode. I know that's possible to do but the problem is that I don't know how to do that.I know I have to use Create method but I don't know what to use for AOwner. I know it sounds like a totally beginner's problem, but I am beginner, sorry! :))
 
The Owner is responsible for destroying the
object created.

myCmd is declared somewhere appropriate as
myCmd: TADOCommand;

nil is a predefined empty/null pointer constant


1) if YOU want to be the owner write:-

myCmd := TADOCommand.Create( nil );

but you then have to destroy the object later
using the Free method or the FreeAndNil procedure.
Good practice may require you to use the Try..Finally..End
construct calling the Free method in the block
of code after the Finally.
If the life time of the object is wider than the scope
of a single method then you will have to find the
appropriate place to create and destroy the class instance
making sure that whatever happens the Free method
does get called.
If the life time of the object is a wide as the
application and you find no benefit in managing it
yourself let the Application object.

2) If you want the application to be the owner write

myCmd := TADOCommand.Create( Application );


The Application object destroys all owned objects
when it is destroyed and this is done transparently.
The Application object is one of the main global objects
and is declared in the Forms unit.






or procedure you will need to
tie override the create and destroy








 
I used form as the owner and it worked fine but I wish to thank you for the examples and the explanations that helped me very much (I used to work in vb and using object variables in that environment is quite different). Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top