Board index » delphi » Using Word 97 collections from within Delphi

Using Word 97 collections from within Delphi

Using Word 97 collections from within Delphi

I can't find a way of referencing an individual object of a collection from
Delphi.

I am truing to convert the following VBA code :

Sub SillyMacro()
'
' Uses the character collection
'
    Selection.Characters(1).Font.AllCaps = True
End Sub

Delphi Code :  I can get the selection to work but not an individual
character.

procedure TForm2.BitBtn1Click(Sender: TObject);
Var
  WordApp: Variant;
begin
  WordApp   := GetActiveOleObject('Word.Application');
 WordApp.Selection.Characters[1].Font.AllCaps := true;       {this line
doesn't work}
 WordApp.Selection.Font.AllCaps := True;                            {   this line works }
end;

Guy.

 

Re:Using Word 97 collections from within Delphi


Quote
Guy Shneerson wrote:
> Using Word 97 collections from within Delphi

> I can't find a way of referencing an individual object of a collection
> from
> Delphi.

> I am truing to convert the following VBA code :

> Sub SillyMacro()
> '
> ' Uses the character collection
> '
>     Selection.Characters(1).Font.AllCaps = True
> End Sub

> Delphi Code :  I can get the selection to work but not an individual
> character.

> procedure TForm2.BitBtn1Click(Sender: TObject);
> Var
>   WordApp: Variant;
> begin
>   WordApp   := GetActiveOleObject('Word.Application');
>  WordApp.Selection.Characters[1].Font.AllCaps := true;       {this
> line
> doesn't work}
>  WordApp.Selection.Font.AllCaps := True;
> {   this line works }
> end;

> Guy.

I had the same problem with Bookmarks and found the answer in a Borland
paper about Ole Auto in Excel and Word recommended in this Group
(microexcel was the name of the page).

In your case you could try this (I did and it worked):

var
 WordObj: Variant;
begin
WordObj:=GetActiveOleObject('Word.Application.8');
WordObj.Selection.Characters.Item(1).Font.AllCaps := true;
end;

Re:Using Word 97 collections from within Delphi


Item is the default method for the Characters collection
It seems to me that a collection character is not a properties and that the
VBA macro converts
Characters[1] into Characters.Item(1)
Or maybe not
All that meters is that it works

 Thanks Guy

Javier Serra Callejo <JSERRA...@NEXO.ES> wrote in article
<353E803E.3CB8A...@NEXO.ES>...

Quote
> Guy Shneerson wrote:

> > Using Word 97 collections from within Delphi

Re:Using Word 97 collections from within Delphi


Yes I've had problems like that.

I found the solution when I imported the Type Library that belongs to
the application I was communicating with.

Its very simple. Microsoft Vb has certain com types called collections.
Like Word.Documents("MyDocument.doc")
Delphi can talk to these collections but in this way :
     Word.Documents.Item('MyDocument.doc');

Its simply a Delphi interpretation of a MS collection comobject.

Edwin Teisman
teis...@defacto.nl

Other Threads