home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / misc / objects / classess / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  979 b   |  62 lines

  1. unit Main;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: CLASSESS }
  5.  
  6. interface
  7.  
  8. uses
  9.   WinTypes, WinProcs, Classes,
  10.   Graphics, Controls, Forms, StdCtrls;
  11.  
  12. type
  13.  
  14.   TMyClass1 = Class(TObject)
  15.     procedure Foo; virtual;
  16.   end;
  17.  
  18.   TMyClass2 = Class(TMyClass1)
  19.     procedure Foo; virtual;
  20.   end;
  21.  
  22.   TForm1 = class(TForm)
  23.     Button1: TButton;
  24.     ListBox1: TListBox;
  25.     procedure Button1Click(Sender: TObject);
  26.   private
  27.     Class1: TMyClass1;
  28.     Class2: TMyClass2;
  29.   end;
  30.  
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.DFM}
  38.  
  39. procedure TMyClass1.Foo;
  40. begin
  41.   Form1.ListBox1.Items.Add('Class1');
  42. end;
  43.  
  44. procedure TMyClass2.Foo;
  45. begin
  46.   Form1.ListBox1.Items.Add('Class2');
  47. end;
  48.  
  49. procedure TForm1.Button1Click(Sender: TObject);
  50. begin
  51.   Class1 := TMyClass1.Create;
  52.   Class1.Foo;
  53.   Class1.Destroy;
  54.   Class2 := TMyClass2.Create;
  55.   Class2.Foo;
  56.   Class1 := Class2;
  57.   Class1.Foo;
  58.   Class2.Destroy;
  59. end;
  60.  
  61. end.
  62.