Looking for good source for code samples

Add-in Express™ Support Service
That's what is more important than anything else

Looking for good source for code samples
 
mem5449


Guest


Anyone know of a GOOD source for Delphi code samples that could augment Add-In Express? I just got my Add-In for VCL package yesterday and was rather disappointed. I have purchased several VCL products over the years (TMS, DevExpress, Woll2Woll) and have always been real happy (and productive) with the documentation and sample code that accompanied the software. This was, by far, the most expensive add-on for Delphi that I have ever purchased and expected more.

Yes, it did...
- Install very easily
- Was easy to setup a project
- and the resulting app (GUI) looked just as I expected.

All good, BUT.. the app doesn't DO anything yet. I kinda expected 'Express' product to make it easier to move further along in completing a SIMPLE app. After carefully reading all the 'Add-In' documentation and searching the Net for approx 7hrs, I am no closer to getting the coding done. My project is to add 2 buttons to an Outlook command bar. When either of the buttons is clicked (while a message is highlighted) a reply is sent to original sender with a 6-letter code appended to the existing subject line. Optionally, a dialog box would pop up stating "Response sent".

The best info (only somewhat useful) I could come up with is the following code (although its VB, and I don?Â?Ð?ét know VB) and a couple links on the MSDN site. AGAIN, anyone have any suggestions on a site with some GOOD samples of code? I've done some automation programming before but never with Outlook (or other Office apps)

REPLY WITH CHANGED SUBJECT
Public Sub ReplyMail()
Dim obj As Object
Dim oReply As Outlook.MailItem
' Text, der dem Betreff vorangestellt werden soll
Const FIX_SUBJECT As String = "Automatische Antwort von x: "

' Verweis auf das aktuell ge?ffnete oder selektierte Element:
Select Case True
Case TypeOf Application.ActiveWindow Is Outlook.Inspector
Set obj = Application.ActiveInspector.CurrentItem
Case Else
With Application.ActiveExplorer.Selection
If .Count Then
Set obj = .Item(1)
End If
End With
If obj Is Nothing Then
Exit Sub
End If
End Select

If TypeOf obj Is Outlook.MailItem Then
Set oReply = obj.Reply
If InStr(1, oReply.Subject, FIX_SUBJECT, vbTextCompare) = 0 Then
oReply.Subject = FIX_SUBJECT & oReply.Subject
End If
oReply.Display
End If
End Sub


USING THE MailItem OBJECT
http://msdn.microsoft.com/en-us/library/aa210946%28v=office.11%29.aspx

REPLY METHOD
http://msdn.microsoft.com/en-us/library/aa220146%28v=office.11%29.aspx
Posted 05 Feb, 2012 00:05:24 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Mike,

Thank you for your feedback.

You are right, there are very few good samples of VCL code in the Internet. I believe this is because the number of general tasks is quite limited.

We have some samples that might be helpful, please see:
http://www.add-in-express.com/free-addins/delphi-outlook-addin.php
http://www.add-in-express.com/support/addin-delphi.php
http://www.add-in-express.com/downloads/adxvcl.php

These are also general samples. As to your particular task, please see the code below, pay attention to calling of the Reply() method and handling the Selection collection:

procedure TAddInModule.DoReply();
var
  IExplorer: _Explorer;
  ISelection: Selection;
  IMail: _MailItem;
  ReplyMail: _MailItem;
begin
  IExplorer := OutlookApp.ActiveExplorer();
  if Assigned(IExplorer) then
    try
      try
        ISelection := IExplorer.Selection;
      except
        ISelection := nil;
      end;
      if Assigned(ISelection) then
        try
          if (ISelection.Count > 0) then begin
            ISelection.Item(1).QueryInterface(IID__MailItem, IMail);
            if Assigned(IMail) then
              try
                ReplyMail := IMail.Reply();
                if Assigned(ReplyMail) then
                  try
                    ReplyMail.Subject := ReplyMail.Subject + 'Q12Q34Q';
                    ReplyMail.Send();
                  finally
                    Replymail := nil;
                  end;
              finally
                IMail := nil;
              end;
          end;
        finally
          ISelection := nil;
        end;
    finally
      IExplorer := nil;
    end;
end;


If you have any questions regarding our product or the Outlook Object Model, don't hesitate to ask.
Posted 06 Feb, 2012 05:29:10 Top
mem5449


Guest


Dmitry,

Thank you SO much for your assistance AND code. Also, thanks for the LINKS. I had already visited those links before initially posting but will take another look.

A couple questions about your code...
1.What is the reason for the nested if-then-try statements? I see where you are assigning the changed SUBJECT, but are the others for checking if intended message has focus?
2. When I searched the Net, I was rather sure I would be using a VAR for Selection and MailItem, but what is the use of Explorer?

BTW, how do I go back in and continue on a project? When I re-open my Add-In project in Delphi, the designer is gone. Hmm?

Mike
Posted 06 Feb, 2012 12:49:36 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Mike,

Please see the answers below.

1. What is the reason for the nested if-then-try statements? I see where you are assigning the changed SUBJECT, but are the others for checking if intended message has focus?


The code of the sample consistently gets to a selected email message checking all accessed interfaces and releasing them later. This is an accurate and safe way to get a selected message avoiding any exceptions.

2. When I searched the Net, I was rather sure I would be using a VAR for Selection and MailItem, but what is the use of Explorer?


The the Explorer object has the Selection property. So, you use the Explorer object as an entry point, in other words you need to use this interface to get access to the Selection collection.

BTW, how do I go back in and continue on a project? When I re-open my Add-In project in Delphi, the designer is gone. Hmm?


You just double click the <YOUR_PROJECT_NAME>_IMPL.pas file in Project Manager and then switch to the Design tab.
Posted 07 Feb, 2012 06:26:00 Top
mem5449


Guest


Dmitry,

Thanks! One last question... What is the difference between TadxCommandBar, TadxOlExplorerCommandBar, and TadxOlInspectorCommandBar? When is one used over another? They almost appear to be interchangeable?

Mike
Posted 10 Feb, 2012 02:01:00 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Mike,

The TadxOlExplorerCommandBar and TadxOlInspectorCommandBar are special components intended to work with Outlook only. The first is purposed for the Outlook Explorer window and the latter for the Outlook Inspector window. The TadxCommandBar component works with all other host applications supporting the command bar architecture.
Posted 10 Feb, 2012 08:52:45 Top