Mega Code Archive

 
Categories / Delphi / Ide Indy
 

WORD Look and feel in a Delphi application

Title: WORD-Look-and-feel in a Delphi application Question: How can I Delete Menu Items in Applications other than my own? Answer: This is the second, more detailed Version of my Article number 2632. To Create a WORD-Like Look-and-feel in Your application, You have to follow these steps: - Create a new Form - insert an OLE-Container (NOT the WORD OLE-Object You have shipped with Delphi!!!)and Set following properties: Align: alClient, AutoActivate: aaManual, AllowInPlace : TRUE, AllowActiveDoc: True. - Insert a Menu and fill the first menu point with 'file' and the sub-menue with the approptiate Items. Now You will have a Listing like that: type TOLE_Testform = class(TForm) OleContainer1: TOleContainer; MainMenu1: TMainMenu; File1: TMenuItem; New1: TMenuItem; Open1: TMenuItem; Save1: TMenuItem; Exit1: TMenuItem; private { Private-Deklarationen } public { Public-Deklarationen } end; When You now run the program, You will just see Your 'File'-Menu. Now add OnClick-Events for each menu item. For Open, it will go like this: procedure TOLE_Testform.Open1Click(Sender: TObject); var continue: boolean; filename: string; begin continue := DocOpenDialog.Execute(); If continue = TRUE then begin filename := DocOpenDialog.Filename; // OleContainer1.DoVerb(ovShow); OleContainer1.DestroyObject; OleContainer1.CreateObjectFromFile(filename,FALSE); OleContainer1.DoVerb(ovShow); end; end; CreateObjectFromFile will create the appropriate OLE-Object for the given file extension, e.g. WORD for *.DOC. A new document You will get from this statement: procedure TOLE_Testform.New1Click(Sender: TObject); begin OleContainer1.DestroyObject; OleContainer1.CreateObject('WORD.Document',FALSE); OleContainer1.DoVerb(ovShow); end; When you opened an existing or created a new document, You will see that the default WORD file menu has been replaced by Your own. And now You can go on experimenting... ;-)) By Andreas