Using Word OLE in Lazarus FreePascal -


im trying freepascal open word document, append text , data , close it. i've managed connected , can write single line document on defeating me. attempting methods details in this visual basic reference, pretty similar how expect freepascal handle things.

basically think have misunderstood how relationship between lazarus , word ole works, can offer me examples on how construct simple document can build on?

the following code, opens document replaces contents

program officauto;  {$ifdef fpc} {$mode delphi} {$else} {$apptype console} {$endif}  uses    sysutils, variants, comobj;  const    servername = 'word.application';  var    server, doc : variant;    opara : variant;    w:widestring;  begin    if assigned(initproc)    tprocedure(initproc);  try    server := createoleobject(servername);    except         writeln('unable start word.');    exit; end;  w:= utf8decode('c:\mydoc.docx'); server.visible := true;  {make word visible} doc := server.documents.open(w);   doc.range.text := 'this heading'; doc.range.font.bold := true; doc.format.spaceafter := 24;  end. 

whereas this, based on code above, in attempting print string @ bookmark, opens document, retains contents, moves bookmark , nothing.

w:= utf8decode('c:\mydoc.docx'); server.visible := true;   doc := server.documents.open(w);   opara := doc.content.paragraphs.add(doc.bookmarks.item('\bookmark1').range); opara := doc.range.text('where appear if @ all!'); 

ah worked out. following code works expected:

program officauto;  {$ifdef fpc}   {$mode delphi} {$else}   {$apptype console} {$endif}  uses    sysutils, variants, comobj;  var   server, connect : variant;   oword, opara1, opara2 : variant;    w:widestring;    begin     if assigned(initproc)     tprocedure(initproc);    try     server := createoleobject('word.application');   except     writeln('unable start word.');     exit;   end;     // oword := server.documents.add;   w:= utf8decode('c:\mydoc.docx');   server.visible := true;     server.documents.open(w);     opara1 := server.activedocument.content.paragraphs.add;   opara1.range.text := 'this heading';   opara1.range.font.bold := true;   opara1.format.spaceafter := 24;   opara1.range.insertparagraphafter();    opara2 := server.activedocument.content.paragraphs.add;   opara2.range.text := 'where appear if @ all!';   opara2.range.font.bold := false;   opara2.format.spaceafter := 24;   opara2.range.insertparagraphafter(); end.  

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -