ole automation outlook in delphi

Hi

DelphiXE2, Outlook2013

I wrote an application to write data in the contact-folder of Outlook. Know I have the following problem: if Outlook is closed I can do it using code
          try
            OutlookApp := GetActiveOleObject('Outlook.Application');
          except
            on E: exception do
            begin
              OutlookApp := CreateOleObject('Outlook.Application');
            end;
          end;

Open in new window

If Outlook is open I get an exeption in both GetActiveOleObject (Operation not available) and CreateOleObject (executeing server failed), ok if Outlook is closed. On the other hand if I stop my application after CreateOleObject and try to open Outlook I get the message "a problem occured executing Outlook. You may execute only one version at a time" (messages translated from german).

How can I access outlook from my application when Outlook is executed?
formiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jdthedjCommented:
I think your code should be the other way around.
try
            OutlookApp := CreateOleObject('Outlook.Application');
          except
            on E: exception do
            begin
              OutlookApp := GetActiveOleObject('Outlook.Application');
            end;
          end;

Open in new window

formiAuthor Commented:
no, it's the same. Thanks anyway.
jdthedjCommented:
I have Outlook 2013 open all the time, and I can still open an instance through Delphi without it saying I cannot have two instances open.  

Are you putting Outlook := Unassigned after you have finished with the automation instance?  You need to do that to prevent extra instances accumulating.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

jimyXCommented:
How about working with early binding?
Do you have any issues?

You seem having configuration issue at MS Outlook.

Because, you never have to do anything for the following code to work from Delphi side.
var
  OutlookApp: OLEVariant;
begin
  try
    OutlookApp := GetActiveOleObject('Outlook.Application');
  except
    OutlookApp := CreateOleObject('Outlook.Application');
  end;

...
end;

Open in new window


And that's been the standard way since office 97.

Make sure you are not starting Outlook with "safe" command.

If this has been working before and now it is not, probably you should investigate what have you done lately to make this happen. Add-ins could make this.

You can't make anything from Delphi if the issue relies upon MS Outlook.

Did you try in another workstation/VM, to see if it occurs with fresh installation of that same Office Source you have?

The tough last resort, if you need this badly, try fresh installation.
formiAuthor Commented:
sorry, found the solution: I had the "GetActiveOleObject" twice in my app!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
formiAuthor Commented:
see my last post.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.