knight_zeng
knight_zeng

Reputation: 1

how to speed up accessing the Fields collection in Word by using Delphi

I need change fields's content,but this way is take too much time,how can i do? Anyone can help me

procedure TForm1.Button1Click(Sender: TObject);
var
  WordApp, WordDocument, Field: OleVariant;
  I: Integer;
begin
  WordApp := CreateOleObject('Word.Application');
  try
    WordDocument := WordApp.Documents.Open('C:\MyDoc.doc');
    if WordDocument.Fields.Count >= 1 then 
      for I := 1 to WordDocument.Fields.Count do
      begin
        **Field := WordDocument.Fields.Item(I);   // file size:20M,Fields.Count:30, This step takes 3 seconds**
      end;
  finally
    WordApp.Quit;
  end;
end; 

Upvotes: 0

Views: 125

Answers (1)

Sherlock70
Sherlock70

Reputation: 579

Please use early binding as shown here which one is better in terms of performance, the early binding or late binding in Delphi COM objects The performance increase is significant.

Upvotes: 1

Related Questions