问题:
TcustomListBox = class(Tstrings)
Private:
Fitem:TStrings;
...
TlistBoxStrings = class(Tstrings)
Private:
ListBox:TcustomListBox;
Public:
Function Add(Const s: string): Integer; override;
… …请问我能否自己定义一个类:
Ttest = class(Tstrings)
Public:
Function Add(Const s: string): Integer; override;
… …
然后实现add(),如果可以那么在调用ListBox.Items.Add()时是用的TlistBoxStrings的add()还是Ttest的ADD();
TcustomListBox = class(Tstrings)
Private:
Fitem:TStrings;
...
TlistBoxStrings = class(Tstrings)
Private:
ListBox:TcustomListBox;
Public:
Function Add(Const s: string): Integer; override;
… …请问我能否自己定义一个类:
Ttest = class(Tstrings)
Public:
Function Add(Const s: string): Integer; override;
… …
然后实现add(),如果可以那么在调用ListBox.Items.Add()时是用的TlistBoxStrings的add()还是Ttest的ADD();
var
deFstr:Tstrings
.
.
.
depsir.add()
.
.
.
edpsir.delete()
.
.
.
你可以声明Tstrings的对象,但那些 add,delete等方法是不能用的,因为是Abstract方法。
所以
var
strs:Tstrings;
begin
strs:=Tstringlist.create;//Tstringlist实现了Tstrings中的抽象方法。
strs.add('字符串');
strs.free;
end;
TListBox是由TcustomListBox 继承过来的,TcustomListBox 的Fitem是TStrings类型的,
而TlistBoxStrings和我自己定义的类Ttest 都是直接继承自TStrings。只不过我自己在TTest中
又override了TStrings的ADD方法,后面又实现了(这里我没写),这样TlistBoxStrings和TTest都有ADD的实现了,那怎么能确定listBox.items.add用的是TlistBoxStrings的add()还是我自己定义的并实现的Ttest的ADD()呢?