Solved

Delphi and COM - how to release objects

Posted on 2003-12-04
1
614 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

18 Experts available now in Live!

Get 1:1 Help Now