Solved

GetActiveOleObject question

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now