home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / misc / objects / listsub / mylist.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  1.1 KB  |  56 lines

  1. unit Mylist;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: LISTSUB }
  5.  
  6. { An example of a customized listbox that lets you get
  7.   around the whole problem of writing ListBox1.Items.Add
  8.   rather than ListBox1.Add. The point is that you can
  9.   customize Delphi objects to behave as you want them
  10.   to behave.
  11.  
  12.   Also shows example of accessing strings from a listbox
  13.   without writing ListBox1.Items.Strings[ListBox1.ItemIndex].
  14.   Instead, it lets you write ListBox1.CurString.
  15.  
  16.   You can go on to add methods that let you access the
  17.   rest of the Items capability. }
  18.  
  19. interface
  20.  
  21. uses
  22.   Classes, Controls, Forms,
  23.   StdCtrls;
  24.  
  25. type
  26.   TMyListBox = class(TListBox)
  27.   public
  28.     procedure Add(S: string);
  29.     function CurString: string;
  30.   end;
  31.  
  32. procedure Register;
  33.  
  34. implementation
  35.  
  36. procedure TMyListBox.Add(s: string);
  37. begin
  38.   Items.Add(S);
  39. end;
  40.  
  41. function TMyListBox.CurString: string;
  42. begin
  43.   if ItemIndex <> - 1 then
  44.     Result := Items.Strings[ItemIndex]
  45.   else
  46.     Result := 'No items selected';
  47. end;
  48.  
  49. procedure Register;
  50. begin
  51.   RegisterComponents('UnLeashed', [TMyListBox]);
  52. end;
  53.  
  54. end.
  55.  
  56.