login about faq

I copied the code from the Send Simple email and I get a AV after the send, to wit:

mailman: TChilkatMailMan2;
success: Integer;
email: CHILKATMAILLib2_TLB.IChilkatEmail2;


// Create a new email object email := CoChilkatEmail2.Create;

// fills in the fields, etc.

rc := mailman.SendEmail(email As CHILKATMAILLib2_TLB.IChilkatEmail2);
if (rc <> 1) then
  SiMain.LogError('Email send failed >> '+ mailman.LastErrorText);

// works fine up to this point, email gets sent

try CoChilkatEmail2(email).Free; // Takes Exception except on E: Exception do begin ... end; end;

What's the proper method to free the object ? Does CloseSMTPConnection tidy everything up ? I used the cast because the IChilkatEmail2 doesn't have a free method.

asked Apr 04 '13 at 09:56

chilkat's gravatar image

chilkat ♦♦

(from http://docwiki.embarcadero.com/RADStudio/XE3/en/Interface_References)
"On the Win32 platform, interface references are typically managed through reference-counting, which depends on the _AddRef and _Release methods inherited from System/IInterface. Using the default implementation of reference counting, when an object is referenced only through interfaces, there is no need to destroy it manually; the object is automatically destroyed when the last reference to it goes out of scope."

A Chilkat interface reference would be a type that begins with an uppercase "I", such as IChilkatEmail2. You don't explicitly call _AddRef or _Release -- this is handled automatically be Delphi. In other words, you don't actually need to do anything in your application code to cleanup.

Additional Information:

When a Chilkat object is declared using “TChilkat*” such as TChilkatSFtp, and it is instantiated dynamically, then it must be explicitly freed (destroyed). See Cleaning up ActiveX Objects in Delphi — calling Free

Also see: Understanding Delphi COM (OLE) Interface References, AddRef and All That


answered Apr 04 '13 at 10:03

chilkat's gravatar image

chilkat ♦♦

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Apr 04 '13 at 09:56

Seen: 2,916 times

Last updated: Apr 04 '13 at 10:03

powered by OSQA