home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / oop.swg / 0005_FILEDLG2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  126 lines

  1. {
  2. >Really like to see is a Real world example.  In particular a
  3. >collection of Filenames in the current directory sorted and  the
  4. >ability to scroll these Strings vertically.  I don't want to go
  5.  
  6. I don't know if this will help that much, but it does what you requested
  7. <g>...  This Compiled in Real mode under BP7 and ran without problems. Although
  8. untested in TP6, it should run fine.
  9. }
  10. Program Example;
  11.  
  12. Uses
  13.   App,
  14.   Dialogs,
  15.   Drivers,
  16.   Menus,
  17.   MsgBox,
  18.   Objects,
  19.   StdDlg,
  20.   Views;
  21.  
  22. Const
  23.   cmAbout       = 101;
  24.  
  25. Type
  26.   TExampleApp = Object(TApplication)
  27.     Procedure CM_About;
  28.     Procedure CM_Open;
  29.     Procedure HandleEvent(Var Event: TEvent); Virtual;
  30.     Constructor Init;
  31.     Procedure InitStatusLine; Virtual;
  32.   end;
  33.  
  34. Procedure TExampleApp.CM_About;
  35. begin
  36.   MessageBox(
  37.     ^C'Example O-O Program' + #13 + #13 +
  38.     ^C'by Bill Himmelstoss (1:112/57)', nil, mfInFormation + mfOkButton
  39.   );
  40. end;
  41.  
  42. Procedure TExampleApp.CM_Open;
  43. Var
  44.   FileDialog: PFileDialog;
  45.   Filename: FNameStr;
  46.   Result: Word;
  47. begin
  48.   FileDialog := New(PFileDialog, Init('*.*', 'Open a File', '~N~ame',
  49.     fdOpenButton, 100));
  50.   {$ifDEF VER70}
  51.   Result := ExecuteDialog(FileDialog, @Filename);
  52.   {$endif}
  53.   {$ifDEF VER60}
  54.   Result := cmCancel;
  55.   if ValidView(FileDialog) <> nil then
  56.     Result := Desktop^.ExecView(FileDialog);
  57.   if Result <> cmCancel then
  58.     FileDialog^.GetFilename(Filename);
  59.   Dispose(FileDialog, Done);
  60.   {$endif}
  61.   if Result <> cmCancel then
  62.     MessageBox(^C'You chose '+Filename+'.', nil, mfInFormation + mfOkButton);
  63. end;
  64.  
  65. Procedure TExampleApp.HandleEvent(Var Event: TEvent); begin
  66.   {$ifDEF VER60}
  67.   TApplication.HandleEvent(Event);
  68.   {$endif}
  69.   {$ifDEF VER70}
  70.   inherited HandleEvent(Event);
  71.   {$endif}
  72.  
  73.   Case Event.What of
  74.     evCommand:
  75.     begin
  76.       Case Event.Command of
  77.         cmAbout: CM_About;
  78.         cmOpen: CM_Open;
  79.       else
  80.         Exit;
  81.       end;
  82.       ClearEvent(Event);
  83.     end;
  84.   end;
  85. end;
  86.  
  87. Constructor TExampleApp.Init;
  88. Var
  89.   Event: TEvent;
  90. begin
  91.   {$ifDEF VER60}
  92.   TApplication.Init;
  93.   {$endif}
  94.   {$ifDEF VER70}
  95.   inherited Init;
  96.   {$endif}
  97.  
  98.   ClearEvent(Event);
  99.   Event.What := evCommand;
  100.   Event.Command := cmAbout;
  101.   PutEvent(Event);
  102. end;
  103.  
  104. Procedure TExampleApp.InitStatusLine;
  105. Var
  106.   R: TRect;
  107. begin
  108.   GetExtent(R);
  109.   R.A.Y := R.B.Y - 1;
  110.   StatusLine := New(PStatusLine, Init(R,
  111.     NewStatusDef($0000, $FFFF,
  112.       NewStatusKey('~F3~ Open', kbF3, cmOpen,
  113.       NewStatusKey('~Alt+X~ Exit', kbAltX, cmQuit,
  114.     nil)),
  115.   nil)));
  116. end;
  117.  
  118. Var
  119.   ExampleApp: TExampleApp;
  120.  
  121. begin
  122.   ExampleApp.Init;
  123.   ExampleApp.Run;
  124.   ExampleApp.Done;
  125. end.
  126.