Board index » delphi » Question: Using .tlb files within delphi

Question: Using .tlb files within delphi

I have the Microsoft Word object definition file wb70en32.tlb that
ships with the Microsoft Word SDK.  In visual basic I can create a
reference to the MS Word Basic object, or in Visual C++ I can import
the tlb file in and Visual C++ will create a wrapper class.

Is there any way to use this tlb file from within Delphi?

I have looked at the C++ wrapper class generated by Visual C++, and it
wraps each method (ie: wordbasic macro command) with a method of a
class, which calls the invokehelper function.  I assume that this
function is a wrapper for the OLE Invoke command.  However, the
wrapper method also declares a variable as static.  How does one
declare a variable as static within a function or method?

 

Re:Question: Using .tlb files within delphi


I have the Microsoft Word object definition file wb70en32.tlb that
ships with the Microsoft Word SDK.  In visual basic I can create a
reference to the MS Word Basic object, or in Visual C++ I can import
the tlb file in and Visual C++ will create a wrapper class.

Is there any way to use this tlb file from within Delphi?

I have looked at the C++ wrapper class generated by Visual C++, and it
wraps each method (ie: wordbasic macro command) with a method of a
class, which calls the invokehelper function.  I assume that this
function is a wrapper for the OLE Invoke command.  However, the
wrapper method also declares a variable as static.  How does one
declare a variable as static within a function or method?

Re:Question: Using .tlb files within delphi


Quote
Matt Lowery wrote:

> I have the Microsoft Word object definition file wb70en32.tlb that
> ships with the Microsoft Word SDK.  In visual basic I can create a
> reference to the MS Word Basic object, or in Visual C++ I can import
> the tlb file in and Visual C++ will create a wrapper class.

> Is there any way to use this tlb file from within Delphi?

> I have looked at the C++ wrapper class generated by Visual C++, and it
> wraps each method (ie: wordbasic macro command) with a method of a
> class, which calls the invokehelper function.  I assume that this
> function is a wrapper for the OLE Invoke command.  However, the
> wrapper method also declares a variable as static.  How does one
> declare a variable as static within a function or method?

Matt,
I think you can do what you want by invoking the CreateOleObject
function that is part of the OleAuto unit. I.E., include OleAuto
in your unit and then define variable of type Variant, e.g.,

var
        Word: Variant;
// other variants would be defined to take care of documents, etc.

and then do something like:

procedure SomeThingOrOther.Button1Click(etc....)
begin
// presumably a TRY/FINALLY block would be a good idea
//
    Word := CreateOleObject('Word.Basic');
//
// you would then use the Word reference variable
// to instantiate other bits of the application
// using more or less the VBA syntax with changes
// to punctuation, bracket style, etc. to convert
// from Basic to Pascal.
end;

If I remember correctly there is a book out entitled 'Delphi2 In
Depth' or 'Delphi Nuts and Bolts' which contains a more detailed
example of using OleAuto/CreateOleObject to manipulate the Word
Ole automation server.

Regards.                         ...edn

Other Threads