home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / FILEMENU / MAIN.PAS < prev   
Pascal/Delphi Source File  |  1998-04-04  |  2KB  |  84 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, SysUtils, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Menus, Buttons;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     MainMenu1: TMainMenu;
  12.     FileMenu: TMenuItem;
  13.     FileExit: TMenuItem;
  14.     OpenButton: TButton;
  15.     OpenDialog: TOpenDialog;
  16.     FileOpen: TMenuItem;
  17.     FileSep1: TMenuItem;
  18.     FileSep2: TMenuItem;
  19.     FileName1: TMenuItem;
  20.     FileName2: TMenuItem;
  21.     FileName3: TMenuItem;
  22.     FileName4: TMenuItem;
  23.     BitBtn1: TBitBtn;
  24.     procedure FileExitClick(Sender: TObject);
  25.     procedure OpenButtonClick(Sender: TObject);
  26.     procedure FileName1Click(Sender: TObject);
  27.   private
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   MainForm: TMainForm;
  35.  
  36. implementation
  37.  
  38. {$R *.DFM}
  39.  
  40. procedure TMainForm.FileExitClick(Sender: TObject);
  41. begin
  42.   Close;
  43. end;
  44.  
  45. {- Prompt for filename and add name to File menu }
  46. procedure TMainForm.OpenButtonClick(Sender: TObject);
  47. var
  48.   S: string;
  49.   I, K: Integer;
  50. begin
  51.   if OpenDialog.Execute then with FileMenu do
  52.   begin
  53.     if not FileSep2.Visible then
  54.       FileSep2.Visible := True;  { Make separator visible }
  55.     K := IndexOf(FileName1);
  56.     for I := Count - 1 downto K + 1 do
  57.     begin  { Move current filenames down one position }
  58.       S := Items[I - 1].Caption;
  59.       S[2] := Chr(Ord('0') + (I - K + 1));  { Alt-Shortcut }
  60.       Items[I].Caption := S;
  61.       Items[I].Visible := Items[I - 1].Visible;
  62.     end;
  63.     FileName1.Caption := '&1 ' + OpenDialog.Filename;
  64.     FileName1.Visible := True;
  65.     ShowMessage('Adding: ' + OpenDialog.Filename);
  66.   end;
  67. end;
  68.  
  69. {- Get filename selected from File menu }
  70. procedure TMainForm.FileName1Click(Sender: TObject);
  71. var
  72.   Filename: string;
  73. begin
  74.   with Sender as TMenuItem do
  75.   begin
  76.     Filename := Caption;
  77.     System.Delete(Filename, 1, 2);
  78.   end;
  79.   ShowMessage('Selected: ' + Filename);
  80. end;
  81.  
  82. end.
  83.  
  84.