Delphi - Knowledge Base Home  About Us  .Net  Solutions  Microsoft  Extras  Contact Us  Freeware  

Topics

Our Delphi article links are shown below. Simply click a link to get started..
 
Delphi Home
Link to this page



Popular Articles

1. Registry walk through & best practice

2. Using the Microsoft Word COM interface

3. Using the Microsoft Excel COM interface

4. Creating & Using Lookup Forms in Delphi

5. Using encryption in your applications

6. Creating and using splash screens in Delphi

7. Using Dev Express to mimic .NET & XP Styles

8. Using the Microsoft Outlook COM interface


  





Delphi - Microsoft Outlook COM (2)

So far so simple. A nice email details form. Lets take a look at the code behind the form.

The beauty of Microsoft's Outlook COM is that it is so simple to use but yet has a vast range of available objects. In our example we are going to concentrate mostly on the MailItem object to send an Email. Before we start to build the Delphi code and communicate with Outlook we must set a reference to the Outlook interface in our class uses section:

Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Outlook2000, ComObj, ActiveX;

              
We also need to create a few class variables to use in our form:

Var
Outlook: _Application;
AFolder : MAPIFolder;
ANameSpace : _NameSpace;
AMailItem : _MailItem;
AAttachments : Attachments;
AppWasRunning: boolean; { has Outlook finished }
lcid: integer; { User ID }
Unknown: IUnknown;
Result: HResult;

Right now, lets take a look at the code behind the button click event. Remember this is the event that the user initiates when they have completed the details and want to send the email to the recipient. To make it easier we are going to break the method down into chunks. First lets look at how we create the COM link: (below)

lcid := LOCALE_USER_DEFAULT;

//----{~~}
Result := GetActiveObject(CLASS_OutlookApplication, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) or (AppWasRunning) then
 Outlook := CoOutlookApplication.Create
else begin
 OleCheck(Result); { Make sure the object has been linked }   OleCheck(Unknown.QueryInterface(_Application, Outlook));
 AppWasRunning := True; { States that excel is now running }
end;

This is the standard COM link that we have used in all our previous COM articles for Word and Excel. The code checks to see if Outlook is already running and if so creates a link to the interface. Else, if Outlook is not a running we start the process using CoOutlookApplication.Create this gives us a return result for _Application. We must use this variable to start our Outlook method calls.
 



 Back (Page 1)  Next (Page 3)

Featured

Other popular Delphi resources. Why not try them for yourself?



                   


    

Extras Microsoft Practice Exams Software Directory Music Tracks Net Components Windows Process
Web Hosting Delphi Amiga Games Processos de Windows Braindumps Musicas Gratis Opiniões
Buy Products Latest Reviews Absolute Adsense Free Web Templates CV Tips Programas Gratis Learning 免费音乐

PrivacyPolicy

  Home  Links  About Us
Copyright © Accelerated Ideas 2005-2009
All rights reserved.


Delphi Knowledge Base. Best practices, walkthroughs, tutorials, component advice and more. Solutions and professional designs for Delphi 4, Delphi 5, Delphi 6 and Delphi, 7. Word COM, Excel COM, Outlook COM including code examples for Word OLE, Excel OLE and Outlook OLE. Automating Outlook to create MailItem and send attachments in Delphi. ActiveX, Com. ADO Data Architecture, TMS component pack walk through and code examples. Using Developer Express and example walkthroughs. Date & time conversion routines, video playback and frame manipulation. COM articles, papers, tips, techniques and hints. How to create Word reports and excel spreadsheets using Delphi code and OLE automation. Understanding Delphi encryption and using ciphers, with source code examples of Blowfish, Twofish, and Rijndael. Securing application data and confidential information using open source encryption components. Free encryption dll component. Accessing and managing MS Excel sheets with Delphi. How to retrieve, display and edit Microsoft Excel spreadsheets with Delphi automation. Accessing and managing MS Word documents with Delphi. How to retrieve, display and edit Microsoft Word documents using Delphi automation. Read and write Excel spreadsheets using Delphi code. How to read and write registry entries using Delphi code. Source code examples using Delphi 5, Delphi 6 and Delphi 7. Working with VCL Developer Express components. How to apply grid styles and themes to Delphi applications. Using image columns and shading to improve the grid and treeview appearances. Including examples from ExpressQuantumPack, for Delphi, ExpressPack for Delphi. Developer guides for Developer Express components. All our articles are written by our senior Delphi professionals to help you get the best from your legacy Delphi applications