I've written a program in Deplhi XE2 to create a new Word document (using Word 2010 and TWordApplication), insert text, and save it as both a .doc file and a .pdf file.
The two Word components are on the form.
Everything works except for the text insertion. When I open the documents after the fact they are both empty.
procedure TForm1.btnGenerateClick(Sender: TObject);
var
sNewText: WideString;
begin
sNewText := 'Hello, World!' + #13;
{ Create the Word document, set text and close it. }
WordApplication1.Visible := False;
WordApplication1.NewDocument;
WordApplication1.Selection.EndOf(wdStory, wdMove);
WordApplication1.Selection.InsertAfter(sNewText);
WordApplication1.Selection.EndOf(wdStory, wdMove);
if FileExists('d:\temp\MyNewDocDup.doc')
then DeleteFile('d:\temp\MyNewDocDup.doc')
else ;
WordDocument1.SaveAs('d:\temp\MyNewDocDup.doc');
if FileExists('d:\temp\MyNewDocDup.pdf')
then DeleteFile('d:\temp\MyNewDocDup.pdf')
else ;
WordDocument1.SaveAs('d:\temp\MyNewDocDup.pdf', 17);
WordDocument1.Close;
WordApplication1.Disconnect;
end;