连加了几天的班,脑子都不转了,关于TStrings的简单问题,在线等待!快进呀!(50分)

T

tt55

Unregistered / Unconfirmed
GUEST, unregistred user!
var LST :Tstrings;files :tinifile;
begin
LST:= tstrings.create;
LST.clear;

LST.AddStrings(ComboBox1.Items);
//出错
files.ReadSections(LST);
//出错
为什么老是出错呢!
 
var LST :Tstrings;files :tinifile;
begin
LST:= tstrings.create;
LST.clear;

// LST.AddStrings(ComboBox1.Items);
//出错
改成
LST.Assign(ComboBox1.Items);
 
不行呀,还是出错!执行到LST.Assign(ComBoBox1.items);也是出错呀!
 
简单,把LST:= tstrings.create;
改成:LST:=Tstringlist.create!
 
可以了,谢谢!但是为什么LST := tstrings.create.不行呢?
 
又学了一招,谢了!
 

TStrings contains abstract methods and should not be directly instantiated.
TStringList implements the abstract properties and methods introduced by
TStrings, and introduces new properties, events, and methods
 
tstrings是一个纯虚抽象类,你用到了它的纯抽象方法clear。
如果调用了纯抽象方法,会产生abstract Error错误的。
而stringlist己经实现了clear方法,所以不会产生异常。
 
多人接受答案了。
 
顶部