Solved

Delphi and COM - how to release objects

Posted on 2003-12-04
1
624 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:
Mohammed Nasman earned 500 total points
ID: 9873817
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 104
select query - oracle 16 100
When i run adoquery my application freezes 26 180
Tvertscrollbox like a whatsapp layout 5 36
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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