Solved

Delphi and COM - how to release objects

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2 89
How to define IfThen functions in one common unit? 4 74
JAudiorecorder record freezing the app 29 91
Delphi Firemonkey : user drawing in window 3 56
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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