Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

September 26, 2007

Using Delphi "As" for Type-Casting with Chilkat ActiveX Components

When an ActiveX is imported into Delphi, a unit is generated (.pas source) that contains the wrappers for the various objects contained in the DLL, as well as for objects referenced by the DLL. The objects referenced by the DLL are those objects that are not implemented by the DLL, but are used as in/out arguments to one or more methods/properties.
A good example is the ChilkatCert object, which is contained in ChilkatCert.dll, but is referenced by Chilkat Mail, Crypt, FTP2, HTTP, etc. Unfortunately, because of the way Delphi generates the code, objects such as IChilkatCert must be typed specific to a type library. For example:

var
  cert : CHILKATMAILLib2_TLB.IChilkatCert;

If the same IChilkatCert2 object is passed between objects from different type libraries, it needs to be cast using the "As" Delphi operator/keyword. Here’s an example where the IChilkatEmail2 object is used by both the Mail and MHT ActiveX’s:

uses
  CHILKATMAILLib2_TLB,
  CHILKATMHTLib_TLB;
…
	
var
  mailman : TChilkatMailMan2;
  mht : TChilkatMht;
  email : CHILKATMAILLib2_TLB.IChilkatEmail2;
  success: Integer;
…
	
mailman := TChilkatMailMan2.Create(nil);
mht := TChilkatMht.Create(nil);
	
// If we do not cast here, you'll get this error:
// Incompatible types: 'CHILKATMHTLib_TLB.IChilkatEmail2' and 'CHILKATMAILLib2_TLB.IChilkatEmail2'
email := mht.GetEmail(‘C:\Content.html') <strong>As CHILKATMAILLib2_TLB.IChilkatEmail2</strong>;
	
…
// No cast is required here because email is declared specific to CHILKATMAILLib2_TLB
success := mailman.SendEmail(email);
if (success <> 1) then
  begin
    ShowMessage(mailman.LastErrorText);
  end;
	

PS> Here’s a reference page for the "As" keyword: Delphi As


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.