Solved

GetActiveOleObject question

Posted on 2004-09-29
6
1,245 Views
Last Modified: 2008-01-09
Hi,
I am trying to use an Activex object in my application.
The VB sample coming with the object works properly opening an Application and a Document; the sample sounds like this:

Dim App, Data, pathToDoc
    Set App = GetObject(, "XXXXX.Application")
    pathToDoc = App.GetActiveDocPath

    If pathToDoc="" Then 'if no data file exists
........................
    End If
 
    Set Data = GetObject(pathToDoc) '..where pathToDoc is the full name of the Document referenced by the object

And I get full controll over the Data object

I don't know how to code in Delphi
Set Data = GetObject(pathToDoc)

Can anyone help me?
Thanks
0
Comment
Question by:dciambrone
6 Comments
 
LVL 2

Accepted Solution

by:
php4delphi earned 250 total points
ID: 12183661
Delphi has no exact equivalent for GetObject function. If you want execute Application (there is no active application running) you have to use CreateOleObject function, otherwise GetActiveOleObject function.
For example,

procedure StartOrLinkToWord;
var
 V: Variant;
begin
 try
  V := GetActiveOleObject('Word.Application');
 except
  V := CreateOleObject(Word'.Application');
 end;

 // Do something with V here...
end;
0
 

Author Comment

by:dciambrone
ID: 12188432
My question is:
With the previous Activex version I used the Delphi method CreateOleObject and everithing was OK.
The new release of the activex has some problems and I am trying to work around the problem waiting for this problems to be fixed.
The above VB code works fine; is there a way to let Delphi work anyway?
Thanks in advance
0
 
LVL 6

Assisted Solution

by:david_barker
david_barker earned 250 total points
ID: 12189481
You can't exactly do the same with Delphi.
What VB does with GetObject when you just supply a filename is to determine the application to start and the object to activate, based on the file name you provide.
In Delphi, you will have to know the classname of this application, ie. "Word.Application" if the file is a Word document.

procedure Test;
var
  App       : Variant;
  pathToDoc : Variant;
  Data      : Variant;
begin
  App:=CreateOleObject('XXXXX.Application');
  pathToDoc:=App.GetActiveDocPath;
  if pathToDoc='' then // if no data file exists
  begin
    // .....
  end;
  //
  Data:=CreateOleObject('YYYYY.Application');
  Data.Open(pathToDoc);   // Open might be the correct method in your case
end;
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question