home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / oop.swg / 0051_Example TInputline.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-02-28  |  3.4 KB  |  147 lines

  1. {
  2. This program will create a record structure of two strings
  3. and initialize them with data then read them into a
  4. TInputLine.  The program will use the SetData and GetData
  5. procedures to load and store from the TInputLine Object.
  6.  
  7. }
  8. {$X+}
  9. program Example;
  10.  
  11. uses Objects, Drivers, Views, Menus, Dialogs, App;
  12.  
  13. const
  14.   cmNewDialog     = 100;
  15.   hcMyDialog      = 300;
  16.  
  17. type
  18.   MyData = record
  19.     Mystr1:String[10];                       { Create a Record Structure }
  20.     MyStr2:String[10];
  21.     end;
  22.  
  23. var
  24.  RMyData:MyData;                             { Declare it }
  25.  
  26. type
  27.   TMyApp = object(TApplication)
  28.     constructor Init;
  29.     procedure HandleEvent(var Event: TEvent); virtual;
  30.     procedure InitMenuBar; virtual;
  31.     procedure NewDialog;
  32.   end;
  33.  
  34.   PDemoDialog = ^TDemoDialog;
  35.   TDemoDialog = object(TDialog)
  36.    Procedure HandleEvent(var Event:TEvent);virtual;
  37.   end;
  38.  
  39. constructor TMyApp.Init;
  40. var
  41.   R : TRect;
  42. begin
  43.   TApplication.Init;                              {Initialize it }
  44.   RMydata.MYstr1:='What';
  45.   RMydata.MYstr2:='Cheese';
  46.   GetExtent(R);
  47.   Dec(R.B.X);
  48.   R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
  49. end;
  50. { TMyApp }
  51.  
  52. Procedure TDemoDialog.HandleEvent(var Event:TEvent);
  53. begin
  54.  TDialog.HandleEvent(Event);
  55.   if Event.What = EvCommand then
  56.     begin
  57.      if event.what = EvCommand then
  58.      case Event.Command of
  59.        cmOK:begin
  60.               GetData(RMyData);    {Get The Data in Declaration Order}
  61.               TDialog.Done;
  62.             end;
  63.        cmCancel:Tdialog.done;
  64.       end
  65.        else
  66.        Exit;
  67.      end;
  68.  clearEvent(Event);
  69. end;
  70.  
  71. procedure TMyApp.HandleEvent(var Event: TEvent);
  72. begin
  73.   TApplication.HandleEvent(Event);
  74.   if Event.What = evCommand then
  75.   begin
  76.     case Event.Command of
  77.       cmNewDialog: NewDialog;
  78.     else
  79.       Exit;
  80.     end;
  81.     ClearEvent(Event);
  82.   end;
  83. end;
  84.  
  85. procedure TMyApp.InitMenuBar;
  86. var
  87.   R: TRect;
  88. begin
  89.   GetExtent(R);
  90.   R.B.Y := R.A.Y + 1;
  91.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  92.     NewSubMenu('~F~ile', hcNoContext, NewMenu(
  93.       NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  94.       nil)),
  95.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  96.        NewItem('~D~ialog','F2', kbF2, cmNewDialog, hcmyDialog,
  97.       nil)),
  98.     nil))
  99.   )));
  100. end;
  101.  
  102. procedure TMyApp.NewDialog;
  103. var
  104.   Borland: PView;
  105.   Dialog: PDemoDialog;
  106.   R: TRect;
  107.   C: Word;
  108. begin
  109.   R.Assign(20, 6, 60, 19);
  110.   Dialog := New(PDemoDialog, Init(R, 'Demo Dialog'));
  111.   with Dialog^ do
  112.   begin
  113.     R.Assign(3, 3, 18, 4);
  114.     Borland := New(PInputLine, Init(R,10));
  115.     Insert(Borland);
  116.     R.Assign(3, 4, 18, 5);
  117.     Borland := New(PInputLine, Init(R,10));
  118.     Insert(Borland);
  119.     R.Assign(2, 2, 10, 3);
  120.     Insert(New(PLabel, Init(R, 'Cheeses', Borland)));
  121.     R.Assign(22, 3, 34, 5);
  122.     Borland := New(PRadioButtons, Init(R,
  123.       NewSItem('~R~unny',
  124.       NewSItem('~M~elted',
  125.       nil)))
  126.     );
  127.     Insert(Borland);
  128.     R.Assign(21, 2, 33, 3);
  129.     Insert(New(PLabel, Init(R, 'Consistency', Borland)));
  130.     R.Assign(15, 8, 25, 10);
  131.     Insert(New(PButton, Init(R, '~O~k', cmOk, bfDefault)));
  132.     R.Assign(28, 8, 38, 10);
  133.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  134.   end;
  135.   Dialog^.SetData(RMyData);        {Dialog Setdata with Record Structure}
  136.   DeskTop^.Insert(Dialog);
  137. end;
  138. var
  139.   MyApp: TMyApp;
  140.  
  141. begin
  142.  
  143.   MyApp.Init;
  144.   MyApp.Run;
  145.   MyApp.Done;
  146. end.
  147.