我在别的地方看到的,可能和你要的不太一样,仅作参考
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, OleCtnrs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
New1: TMenuItem;
Open1: TMenuItem;
Save1: TMenuItem;
N1: TMenuItem;
OpenDialog1: TOpenDialog;
Panel1: TPanel;
OleContainer1: TOleContainer;
Edit1: TMenuItem;
Cut1: TMenuItem;
Copy1: TMenuItem;
Paste1: TMenuItem;
InsertObject1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
Return1: TMenuItem;
SaveDialog1: TSaveDialog;
procedure New1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure Return1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure InsertObject1Click(Sender: TObject);
procedure Cut1Click(Sender: TObject);
procedure Copy1Click(Sender: TObject);
procedure Paste1Click(Sender: TObject);
procedure OleContainer1Activate(Sender: TObject);
procedure OleContainer1Deactivate(Sender: TObject);
private
{ Private declarations }
FFileName: string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.New1Click(Sender: TObject);
begin
OleContainer1.DestroyObject;
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
if OpenDialog1.Execute then begin
FFileName := OpenDialog1.FileName;
OleContainer1.LoadFromFile(FFileName);
end;
end;
procedure TForm1.Save1Click(Sender: TObject);
begin
if FFileName = '' then begin
if SaveDialog1.Execute then
FFileName := SaveDialog1.FileName
else
exit;
end;
OleContainer1.SaveToFile(FFileName);
end;
procedure TForm1.Return1Click(Sender: TObject);
begin
OleContainer1.Close;
end;
procedure TForm1.InsertObject1Click(Sender: TObject);
begin
if OleContainer1.InsertObjectDialog then
OleContainer1.DoVerb(OleContainer1.PrimaryVerb);
end;
procedure TForm1.Cut1Click(Sender: TObject);
begin
OleContainer1.Copy;
OleContainer1.DestroyObject;
end;
procedure TForm1.Copy1Click(Sender: TObject);
begin
OleContainer1.Copy;
end;
procedure TForm1.Paste1Click(Sender: TObject);
begin
if OleContainer1.CanPaste then
OleContainer1.PasteSpecialDialog;
end;
procedure TForm1.OleContainer1Activate(Sender: TObject);
begin
Return1.Enabled := True;
end;
procedure TForm1.OleContainer1Deactivate(Sender: TObject);
begin
Return1.Enabled := False;
end;
end.