Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word and CPU memory 1

Status
Not open for further replies.

michaenh

Programmer
Aug 7, 2002
205
NO
Hi.

Here is my code.:

procedure TForm1.Button1Click(Sender: TObject);
var
myWordApp: TWordApplication;
myFile, Savefile: OleVariant;
Doc: WordDocument;
begin
// Create an instance of Word application.
myWordApp := TWordApplication.Create(Self);
myFile := 'C:\SA08.doc';
SaveFile := 'C:\test.doc';

//Open a readonly document without displaying it.
Doc := myWordApp.Documents.Open(myFile, // filename
EmptyParam, // COnfirmConversion
EmptyParam, // REadonly
EmptyParam, // ADdToRecent
EmptyParam, // PasswordDocument
EmptyParam, // PasswordTemplate
EmptyParam, // Revert
EmptyParam, // WritePasswordDocument
EmptyParam, // WritePasswordTemplate
EmptyParam, // Format
EmptyParam, // Encoding
EmptyParam // Visible
);

//Opens word application with myFile.
//myWordApp.Visible := TRue;

//Saves the file without readonly.
Doc.SaveAs(SaveFile, // filename
EmptyParam, // fileformat
EmptyParam, // Lockcomments
EmptyParam, // Password
EmptyParam, // AddtoRecentFiles
EmptyParam, // WritePassword
EmptyParam, // ReadOnlyRecommended
EmptyParam, // EmbedTrueTypeFonts
EmptyParam, // SaveNativePictureFormat
EmptyParam, // SaveFormsData
EmptyParam // SaveAsAOCELetter
);

Doc.Close(EmptyParam,EmptyParam,EmptyParam);

//This will free the application from memory.
myWordApp.Quit;

The problem is that if I use myWordApp.Quit it will try to close any Word application that is allready open, but if I use other methods the Winword.exe will not be destroyed or killed in the memory....

Please help me...

Is there any solutions to my problem??

Many thanks if anyone could help.

Michael

 

Will something like this help?

procedure TForm1.Button1Click(Sender: TObject);
Var
wordapplication:variant;
act:boolean;
begin

act:=false;

try
wordapplication := GetActiveOleObject('Word.Application');
act:=true;
except
wordapplication := CreateOleObject('Word.Application');
end;

{
//*********
all your code here
//*********
}


if Act then
wordapplication := Unassigned
else
wordapplication.quit;

end;
 
Hi earlrainer.

I tried a little manipulation with your code and it works when a word document is allready open, but I get an error when I do not have any document open.

The GetActiveOleObject('Word.Application') raised an exception class EOleSysError, 'Operation unavailable'..

Is it try.. except.. which fails?

Do you have any clue.. ? Or how do I get pass this error..

Many Thanks..

Michael


 
Hi ,

This is a design time error only (which you will get only if you run your program in debug mode with 'STOP ON DELPHI EXCEPTION' turned ON )

you wont get it during run time
or turn 'STOP ON DELPHI EXCEPTION' OFF
 
Oki... that`s great!
Thanks. :eek:) I am really happy now!

Merry Christmas to you and a Happy New Year!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top