Solved

GetActiveOleObject question

Posted on 2004-09-29
6
1,250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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