Solved

Delphi and COM - how to release objects

Posted on 2003-12-04
1
631 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

707 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