OleForm.pas
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:3k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit OleForm;
  2. interface
  3. uses
  4.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  5.   Forms, Dialogs, Menus, ExtCtrls, StdCtrls, OleCtnrs, Buttons;
  6. type
  7.   TForm1 = class(TForm)
  8.     MainMenu1: TMainMenu;
  9.     File1: TMenuItem;
  10.     Exit1: TMenuItem;
  11.     N2: TMenuItem;
  12.     SaveAs1: TMenuItem;
  13.     Open1: TMenuItem;
  14.     New1: TMenuItem;
  15.     Help1: TMenuItem;
  16.     About1: TMenuItem;
  17.     Edit1: TMenuItem;
  18.     Object1: TMenuItem;
  19.     N3: TMenuItem;
  20.     PasteSpecial1: TMenuItem;
  21.     Paste1: TMenuItem;
  22.     Copy1: TMenuItem;
  23.     Cut1: TMenuItem;
  24.     ToolbarPanel: TPanel;
  25.     NewSpeedButton: TSpeedButton;
  26.     CutSpeedButton: TSpeedButton;
  27.     CopySpeedButton: TSpeedButton;
  28.     PasteSpeedButton: TSpeedButton;
  29.     AboutSpeedButton: TSpeedButton;
  30.     MainPanel: TPanel;
  31.     OleContainer1: TOleContainer;
  32.     OpenDialog1: TOpenDialog;
  33.     SaveDialog1: TSaveDialog;
  34.     Panel1: TPanel;
  35.     BitBtn1: TBitBtn;
  36.     BitBtn2: TBitBtn;
  37.     BitBtn3: TBitBtn;
  38.     procedure Exit1Click(Sender: TObject);
  39.     procedure New1Click(Sender: TObject);
  40.     procedure About1Click(Sender: TObject);
  41.     procedure Paste1Click(Sender: TObject);
  42.     procedure PasteSpecial1Click(Sender: TObject);
  43.     procedure Edit1Click(Sender: TObject);
  44.     procedure Copy1Click(Sender: TObject);
  45.     procedure Cut1Click(Sender: TObject);
  46.     procedure Object1Click(Sender: TObject);
  47.     procedure Open1Click(Sender: TObject);
  48.     procedure SaveAs1Click(Sender: TObject);
  49.   private
  50.     { Private declarations }
  51.     procedure UpdateUI;
  52.   public
  53.     { Public declarations }
  54.   end;
  55. var
  56.   Form1: TForm1;
  57. implementation
  58. {$R *.DFM}
  59. procedure TForm1.Exit1Click(Sender: TObject);
  60. begin
  61.   Close;
  62. end;
  63. procedure TForm1.New1Click(Sender: TObject);
  64. begin
  65.   if OleContainer1.InsertObjectDialog then
  66.     OleContainer1.DoVerb (
  67.       OleContainer1.PrimaryVerb);
  68.   UpdateUI;
  69. end;
  70. procedure TForm1.About1Click(Sender: TObject);
  71. begin
  72.   MessageDlg ('Sample OLE container' +
  73.     #13'From the book "Mastering Delphi"',
  74.     mtInformation, [mbOk], 0);
  75. end;
  76. procedure TForm1.Paste1Click(Sender: TObject);
  77. begin
  78.   OleContainer1.Paste;
  79.   UpdateUI;
  80. end;
  81. procedure TForm1.PasteSpecial1Click(Sender: TObject);
  82. begin
  83.   OleContainer1.PasteSpecialDialog;
  84.   UpdateUI;
  85. end;
  86. procedure TForm1.Edit1Click(Sender: TObject);
  87. begin
  88.   UpdateUI;
  89. end;
  90. procedure TForm1.UpdateUI;
  91. begin
  92.   Cut1.Enabled := OleContainer1.State <> osEmpty;
  93.   Copy1.Enabled := OleContainer1.State <> osEmpty;
  94.   Object1.Enabled := OleContainer1.State <> osEmpty;
  95.   Paste1.Enabled := OleContainer1.CanPaste;
  96.   PasteSpecial1.Enabled := OleContainer1.CanPaste;
  97.   PasteSpeedButton.Enabled := Paste1.Enabled;
  98.   CutSpeedButton.Enabled := Cut1.Enabled;
  99.   CopySpeedButton.Enabled := Copy1.Enabled;
  100. end;
  101. procedure TForm1.Copy1Click(Sender: TObject);
  102. begin
  103.   OleContainer1.Copy;
  104.   UpdateUI;
  105. end;
  106. procedure TForm1.Cut1Click(Sender: TObject);
  107. begin
  108.   OleContainer1.Copy;
  109.   OleContainer1.Destroy;
  110.   UpdateUI;
  111. end;
  112. procedure TForm1.Object1Click(Sender: TObject);
  113. begin
  114.   OleContainer1.ObjectPropertiesDialog;
  115. end;
  116. procedure TForm1.Open1Click(Sender: TObject);
  117. begin
  118.   if OpenDialog1.Execute then
  119.     OleContainer1.LoadFromFile (OpenDialog1.FileName);
  120.   UpdateUI;
  121. end;
  122. procedure TForm1.SaveAs1Click(Sender: TObject);
  123. begin
  124.   if SaveDialog1.Execute then
  125.     OleContainer1.SaveToFile (SaveDialog1.FileName);
  126. end;
  127. end.