home *** CD-ROM | disk | FTP | other *** search
- unit Mylist;
-
- { Program copyright (c) 1995 by Charles Calvert }
- { Project Name: LISTSUB }
-
- { An example of a customized listbox that lets you get
- around the whole problem of writing ListBox1.Items.Add
- rather than ListBox1.Add. The point is that you can
- customize Delphi objects to behave as you want them
- to behave.
-
- Also shows example of accessing strings from a listbox
- without writing ListBox1.Items.Strings[ListBox1.ItemIndex].
- Instead, it lets you write ListBox1.CurString.
-
- You can go on to add methods that let you access the
- rest of the Items capability. }
-
- interface
-
- uses
- Classes, Controls, Forms,
- StdCtrls;
-
- type
- TMyListBox = class(TListBox)
- public
- procedure Add(S: string);
- function CurString: string;
- end;
-
- procedure Register;
-
- implementation
-
- procedure TMyListBox.Add(s: string);
- begin
- Items.Add(S);
- end;
-
- function TMyListBox.CurString: string;
- begin
- if ItemIndex <> - 1 then
- Result := Items.Strings[ItemIndex]
- else
- Result := 'No items selected';
- end;
-
- procedure Register;
- begin
- RegisterComponents('UnLeashed', [TMyListBox]);
- end;
-
- end.
-
-