Solved

Ole, Delphi 3, Olecontainer

Posted on 1997-10-17
12
1,705 Views
Last Modified: 2010-05-20
Using variants as OLE objects is to slow for our use, so we have to include the xxxx_tlb.pas file and use the type library approch.
It´s no problem to have fx. a word object like MyWordEditor:=CreateOleObject('Word.Application') AS _Application, but how do you place this object in an olecontainer ?
0
Comment
Question by:miv
12 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1347836
1025pt !!!! you must really need this. I just starting to write this, however in the first your question about this I submit comment and you don't answer this.

Do you try use first olecontainer and then use oleautomation ?
0
 
LVL 1

Author Comment

by:miv
ID: 1347837
mirek, I read your comments, but did not understand them.
Please either explain in further detail or submit some example code.

This should be fairly easy to acomplish,
but no one seems to have had the same problem.

An "A" grade will be awarded to the person who solves this...
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1347838
Now that you have everybodies attention...

The way I understand it, you can't put a "Word.Application" into an OLE Container, only a "Word.Document", as in:
    MyOLEContainer.AutoActivate := aaManual;
    MyOLEContainer.CreateObject('Word.Document', False);
    MyOLEContainer.DoVerb(ovShow);

JB
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:miv
ID: 1347839
If I use that approch, the Ole container will contain a variant.
That´s called late binding and means that the procedures and properties of the Word object will not be accesible during design time.
This is also extremly slow...
I have imported the Word typelib and want to create a _Application (that´s the Word object) and the insert it into a Ole container.

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1347840
Whatever way you do it, I think that you will only get a _Document from the typelib into an OLE container.  The _Application doesn't support the correct interface...  (You can get to the _Application from the _Document through the Document's "Application" property.)

Nevertheless, can you not insert the object as I suggested, and then use TOleContainer's "OleObjectInterface" property to get the IOleObject interface?  You could use this IOleObject to get the _Document (or _Application???).

JB
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347841
H'll, as I already said the first time this question came on experts exchange, I don't know much about OLE. But, I see that the problem is within TOleContainer. So, why don't you make your own container? Don't shoot me, I just want to help! I see that this is really important for you all, that's why I send this idea to you.
Here is some information for making an own container, hope this helps you a little bit further :

Read OLE compound docs


 Don't use the TOleContainer component for what you want to do. Creating an appl
lication that accesses OLE Structured Storage files is really quite simple only
 a couple of OLE API calls, and about 5-6 API calls to the member functions of I

 The API functions that you're going to need are:

 StgOpenStorage
 StgIsStorageFile

 If you have the OLE 2.01 SDK, you'll find the definitions there.

 Note that Borland made some mistakes when porting the C++ header files from the
e OLE SDK to Delphi. One of the mistakes resulted in no end of grief for me when
n writing my structured storage browser applet. Here's the correct definition of

  MyIStorage = class(IUnknown)
    function CreateStream(const pwcsName: PChar; grfMode: Longint; reserved1: Lo
      reserved2: Longint; var ppstm: IStream): HResult; virtual; cdecl; export;
    function OpenStream(const pwcsName: PChar; reserved1: Pointer; grfMode: Long
      reserved2: Longint; var ppstm: IStream): HResult; virtual; cdecl; export;
    function CreateStorage(const pwcsName: PChar; grfMode: Longint;
      reserved1: Longint; reserved2: Longint; var ppstg: MyIStorage): HResult;
      virtual; cdecl; export; abstract;
    function OpenStorage(const pwcsName: PChar; pstgPriority: MyIStorage;
      grfMode: Longint; snbExclude: PStr; reserved: Longint;
      var ppstg: MyIStorage): HResult; virtual; cdecl; export; abstract;
    function CopyTo(ciidExclude: Longint; const rgiidExclude: IID;
      var snbExclude: PStr; pstgDest: MyIStorage): HResult; virtual; cdecl; expo
    function MoveElementTo(const lpszName: PChar; pstgDest: MyIStorage;
      const lpszNewName: PChar; grfFlags: Longint): HResult; virtual; cdecl; exp
    function Commit(grfCommitFlags: Longint): HResult; virtual; cdecl; export; a
    function Revert: HResult; virtual; cdecl; export; abstract;
    function EnumElements(reserved1: Longint; reserved2: Pointer; reserved3: Lon
      var ppenm: IEnumStatStg): HResult; virtual; cdecl; export; abstract;
    function DestroyElement(const pwcsName: PChar): HResult; virtual; cdecl; exp
    function RenameElement(const pwcsOldName: PChar;
      const pwcsNewName: PChar): HResult; virtual; cdecl; export; abstract;
    function SetElementTimes(const lpszName: PChar; const pctime: TFileTime;
      const patime: TFileTime; const pmtime: TFileTime): HResult;
      virtual; cdecl; export; abstract;
    function SetClass(const clsid: IID): HResult; virtual; cdecl; export; abstra
    function SetStateBits(grfStateBits: Longint; grfMask: Longint): HResult;
      virtual; cdecl; export; abstract;
    function Stat(var pstatstg: TStatStg; grfStatFlag: Longint): HResult;
      virtual; cdecl; export; abstract;
  end;

 The problem is that there were a few parameters that were incorrectly declared
 as VAR, when they really should have been declared CONST - important since some
etimes the interface member functions expect to be passed NIL for some of their

 Hope this helps

 John
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
That 's it. And I promise I won't give you any of my ideas if you just say that you don't like my comments.
Have fun,
c.u. ZifNab;
0
 
LVL 1

Author Comment

by:miv
ID: 1347842
Thanks to everybody, I´ll check out your proposals during/after the weekend.
Other comments would also be appriciated.

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1347843
Here is an example, based on my last comment.

A few comments first:
1)  The Word TLB file (I'm using Word 97) declares a GUID called Class_Document.  But the _Document interface has a different GUID, so I redeclared a GUID called Class_Doc with the _Document GUID.

2)  My example assumes there's a TOleContainer called oleWord on the form.

3)  I know you want _Application, but I really cannot get one into the Ole Container.  My example puts a Word.Document into the Ole Container, but I still have access to the _Application.  You will see that I use the _Application in my example to determine if NumLock is on or off.

Here is the code:

procedure TForm1.CreateWordInContainer;
const
    Class_Doc: TGUID = '{0002096B-0000-0000-C000-000000000046}';
var
    WordDoc: _Document;
begin
    oleWord.AutoActivate := aaManual;
    oleWord.CreateObject('Word.Document', False);
    oleWord.DoVerb(ovShow);
    if (oleWord.OleObjectInterface.QueryInterface(Class_Doc, WordDoc) = S_OK) then
    begin
        if (WordDoc.Application.NumLock) then
            ShowMessage('NumLock On.')
        else
            ShowMessage('NumLock Off.');
    end else
        ShowMessage('Connot get Document interface.');
end;

JB
0
 
LVL 1

Author Comment

by:miv
ID: 1347844
Hello ZifNab and JB,
I tested JB´s answer and it seems to be working OK...but it´s still slllooooowwww.
Is this really the fastest way to communication with Microsoft Word ?
If it is, please submit an answer to this Q.

Zifnab, I´m sorry, but I hav´nt got the time to read docs and make changes in the scale you are proposing. But I liked your comments and will be happy to help you for free in the future if that situation should occur ;-)
0
 
LVL 1

Author Comment

by:miv
ID: 1347845
Hello ZifNab and JB,
I tested JB´s answer and it seems to be working OK...but it´s still slllooooowwww.
Is this really the fastest way to communication with Microsoft Word ?
If it is, please submit an answer to this Q.

Zifnab, I´m sorry, but I hav´nt got the time to read docs and make changes in the scale you are proposing. But I liked your comments and will be happy to help you for free in the future if that situation should occur ;-)
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 1020 total points
ID: 1347846
Hi

Using a type-library is surely the fastest way of communicating with any OLE application, and by using the QueryInterface method I proposed you are no longer using Variants, and speed should have improved???

I will submit this as an answer to your question about "using the type lib approach".  I honestly would be very surprised if anybody could find a faster approach, as this is the method I would use in Delphi, VC++, etc...  In fact, I always use the type lib approach where possible.

Sorry, Zifnab, but I definitely feel that your approach is reinventing the wheel, and would end up being a lot slower.

JB
0
 
LVL 1

Author Comment

by:miv
ID: 1347847
JB, I will grade your answer friday, I´m just waiting to see if anybody has any comments.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 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