Solved

Delphi and COM - how to release objects

Posted on 2003-12-04
1
612 Views
Last Modified: 2010-04-05
Hi all,

my method generates an exception on "end;". I believe I'm not releasing/free-ing the ojbects in a correct way.

  myConnection : ADODB_TLB.Connection;
  loginName : WideString;
  cmdCommand : ADODB_TLB.Command;
  oleParam, oleRecords : OleVariant;
  paramLogin : Parameter;
  Stream         : ADODB_TLB.TStream;
  resultString : WideString;

begin
   myConnection :=  m_ConnectionPool.getADOXMLConnection();
   cmdCommand := ADODB_TLB.CoCommand.Create();
   cmdCommand.Set_ActiveConnection( myConnection );
   paramLogin := cmdCommand.CreateParameter('@login',
                  adVarChar, adParamInput, 30, loginName );
   Stream := ADODB_TLB.TStream.Create(nil);
    Stream.Open(EmptyParam,adModeUnknown,
      adOpenStreamUnspecified,'','');
   cmdCommand.Properties.Item['Output Stream'].Value := Stream.DefaultInterface;
   cmdCommand.Execute( oleRecords, EmptyParam, adExecuteStream );
   resultString := Stream.ReadText(Integer(adReadAll));
   outXML.XMLfromString( resultString );
   Stream.Close;
  Stream.Free;
  cmdCommand._Release;
  myConnection._Release;
  m_ConnectionPool.returnConnection();

At the end, I need to close the stream, release the command object and release the connection and tell the pool that I'm not using the connection anymore.

In what order should I release the objects?

cheers,

henrik
0
Comment
Question by:henrikatwork
1 Comment
 
LVL 22

Accepted Solution

by:
mnasman earned 500 total points
Comment Utility
assign your interfaces to Nil

cmdCommand := nil;

in general Delphi will release the memory of the com object when it's go out of scope, or you can do that be assigning the nil to the interface, I think you don't need to call release method, Delphi will call it
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now