Copyright © 2024 IMIBO. Privacy Statement
Extended MAPI in DELPHI
Example #9
How to work with MAPI Profiles
Profman
[Original C++ code is written by Sam Charchi Microsoft Developer Support]
This sample, Profman v2.0, was created to demonstrate how to use the MAPI interfaces and methods that pertain to the manipulation and creation of MAPI profile. Example is based on Microsoft Profman 2.0 Application (you can find it somewhere in the depths of the Internet archives, it was removed by Microsoft years ago.).
In this example whose original C code is written by Microsoft you may study the original Microsoft technology of writing. We tried to stay as close as possible to the original code, however, at the points where we couldn’t stand it any longer, we used DELPHI techniques.
We have left the original comments of the Microsoft developers. Its functionality is as follows:
1. Creates a new blank profile.
2. Adds services to a profile.
3. Deletes services from a profile.
4. Lists the services in a profile.
5. Adds providers to a service.
6. Deletes providers from a service.
7. Lists the providers in a service.
8. Lists the available properties of a service (even those that are normally inaccessible).
9. Lists the available properties of a provider (even those that are normally inaccessible).
Download Example #9 as Compiled Application
Download Project (DELPHI 10.4) ZIP file
Source Code: In package
(* In this example whose original C code is written by Microsoft you may study the original Microsoft technology of writing. We tried to stay as close as possible to the original code, however, at the points where we couldn't stand it any longer, we used DELPHI techniques. We have left the original comments of the Microsoft developers. This sample, Profman v2.0, was created to demonstrate how to use the MAPI interfaces and methods that pertain to the manipulation and creation of MAPI profiles. Its functionality is as follows: 1. Creates a new blank profile. 2. Adds services to a profile. 3. Deletes services from a profile. 4. Lists the services in a profile. 5. Adds providers to a service. 6. Deletes providers from a service. 7. Lists the providers in a service. 8. Lists the availible properties of a service (even those that are normally inaccessable). 9. Lists the availible properties of a provider (even those that are normally inaccessable). Source Files ============ ItemInfo - This file contains the code that manages the MAPI interfaces for each item in the tree. It also contains some summary information about each item in the tree. unLoadProgress - This file contains the code for the user interface of the dialog that displays the progress bar when loading the profiles at startup. unMainFrm - This file contains the code that manages the main frame UI. It contains the tree on the left and the list on the right. Profiles - This file contains the code that performs most of the MAPI work in the application. It also helps to manage the tree. - Mostly Appwizard generated, this file contains the document class for the application. SelectProvider - This file contains the code for the user interface and data that will display all availible providers for the selected service and allow the user to select one to be installed. SelectService - This file contains the code for the user interface and data that will display all availible services installed on the system and allow the user to select one to be installed. *) // !!! Profile Section supports only ANSI Strings !!!// unit unMainFrm; interface { Please add "..\Library" to project search path } {$I IMI.INC} uses Classes, Controls, Forms, Graphics, ActnList, ComCtrls, ExtCtrls, ImgList, Menus, unProfiles, ToolWin, System.Actions, System.ImageList; type TMainFrm = class(TForm) MainMenu1: TMainMenu; File1: TMenuItem; Exit1: TMenuItem; Edit1: TMenuItem; Delete1: TMenuItem; New1: TMenuItem; Profile1: TMenuItem; Service1: TMenuItem; Provider1: TMenuItem; Help1: TMenuItem; HAbout: TMenuItem; StatusBar1: TStatusBar; ImageList1: TImageList; ActionList1: TActionList; ActionAbout: TAction; ControlBar1: TControlBar; ToolBar1: TToolBar; tbCreateNewProfile: TToolButton; tbAddService: TToolButton; tbAddNewProvider: TToolButton; ToolButton4: TToolButton; tbDelSelObject: TToolButton; tbAboutProfman: TToolButton; ToolButton7: TToolButton; ControlBar2: TControlBar; ControlBar3: TControlBar; Panel1: TPanel; ControlBar4: TControlBar; TreeViewProf: TTreeView; Splitter1: TSplitter; lvProp: TListView; ImageList2: TImageList; ActionExit: TAction; ActNewProfile: TAction; ActNewService: TAction; ActProvider: TAction; ActDelete: TAction; procedure ActionAboutExecute(Sender: TObject); procedure Exit1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure ActionExitExecute(Sender: TObject); procedure ActNewProfileExecute(Sender: TObject); procedure ActNewServiceExecute(Sender: TObject); procedure TreeViewProfClick(Sender: TObject); procedure ActProviderExecute(Sender: TObject); procedure ActDeleteExecute(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } Prof: TCProfiles; ITWSelected: TTreeNode; public { Public declarations } end; var MainFrm: TMainFrm; implementation uses unAboutFrm; {$R *.DFM} procedure TMainFrm.ActionAboutExecute(Sender: TObject); begin with TAboutFrm.Create(self) do begin ShowModal; Free; end; end; procedure TMainFrm.Exit1Click(Sender: TObject); begin Close; end; procedure TMainFrm.FormCreate(Sender: TObject); begin ActNewService.Enabled := True; ActProvider.Enabled := False; Prof := TCProfiles.Create; Prof.LoadProfiles(TreeViewProf); {$IF DEFINED (WIN64)} self.Caption := self.Caption + ' - WIN64'; {$ELSE} self.Caption := self.Caption + ' - WIN32'; {$IFEND} end; procedure TMainFrm.ActionExitExecute(Sender: TObject); begin Close; end; procedure TMainFrm.ActNewProfileExecute(Sender: TObject); begin Prof.NewProfile(TreeViewProf); end; procedure TMainFrm.ActNewServiceExecute(Sender: TObject); begin if Assigned(TreeViewProf.Selected) then if TreeViewProf.Selected.ImageIndex = integer(ICON_PROFILE) then Prof.NewService(TreeViewProf, TreeViewProf.Selected, TreeViewProf.Selected.Data); end; procedure TMainFrm.TreeViewProfClick(Sender: TObject); begin if Assigned(TreeViewProf.Selected) then begin case ProfileIcons(TreeViewProf.Selected.ImageIndex) of ICON_PROFILE: begin ActNewService.Enabled := True; ActProvider.Enabled := False; end; ICON_SERVICE: begin ActNewService.Enabled := False; ActProvider.Enabled := True; if ITWSelected <> TreeViewProf.Selected then Prof.LoadProp(lvProp, TreeViewProf.Selected); end; ICON_PROVIDER: begin ActNewService.Enabled := False; ActProvider.Enabled := False; if ITWSelected <> TreeViewProf.Selected then Prof.LoadProp(lvProp, TreeViewProf.Selected); end; end; ITWSelected := TreeViewProf.Selected; end; end; procedure TMainFrm.ActProviderExecute(Sender: TObject); begin if Assigned(TreeViewProf.Selected) then if TreeViewProf.Selected.ImageIndex = integer(ICON_SERVICE) then Prof.NewProvider(TreeViewProf, TreeViewProf.Selected, TreeViewProf.Selected.Data); end; procedure TMainFrm.ActDeleteExecute(Sender: TObject); var ParentNode: TTreeNode; begin if Assigned(TreeViewProf.Selected) then begin ParentNode := TreeViewProf.Selected.Parent; Prof.Delete(TreeViewProf.Selected); if Assigned(ParentNode) then ParentNode.Selected := True; end; end; procedure TMainFrm.FormClose(Sender: TObject; var Action: TCloseAction); begin if Assigned(ITWSelected) then if Assigned(ITWSelected.Data) then ITWSelected.Data := nil; lvProp.Items.Clear; Prof.DeleteTree(TreeViewProf); Prof.UnInitializeMAPI; Prof.Free; end; end.