Ole, Delphi 3, Olecontainer

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 ?
LVL 1
mivAsked:
Who is Participating?
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.

mirek071497Commented:
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
mivAuthor Commented:
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
JimBob091197Commented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

mivAuthor Commented:
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
JimBob091197Commented:
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
ZifNabCommented:
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
mivAuthor Commented:
Thanks to everybody, I´ll check out your proposals during/after the weekend.
Other comments would also be appriciated.

0
JimBob091197Commented:
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
mivAuthor Commented:
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
mivAuthor Commented:
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
JimBob091197Commented:
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

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
mivAuthor Commented:
JB, I will grade your answer friday, I´m just waiting to see if anybody has any comments.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.