unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }  end;var
  Form1: TForm1;
  Zpath:Tstrings;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Zpath:=Tstrings.Create;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
zpath.Add('aaa');
end;end.
错误提示:
[Warning] Unit1.pas(31): Constructing instance of 'TStrings' containing abstract method 'TStrings.Clear'
[Warning] Unit1.pas(31): Constructing instance of 'TStrings' containing abstract method 'TStrings.Delete'
[Warning] Unit1.pas(31): Constructing instance of 'TStrings' containing abstract method 'TStrings.Insert'

解决方案 »

  1.   


    改为以下代码试试:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      Zpath:Tstrings;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    beginzpath.Create;
    zpath.add('aaa');end;end.
      

  2.   

    不行呀,我的zpath要定义成全局的,目的是在整个程序里,不断的累加字符串!随便哪个模块都能加进字符。就是说在那里都能zpath.add('aaa'),我的程序错在哪里呀?
      

  3.   

    Zpath:=Tstrings.Create;
    改为Zpath:=Tstringlist.Create;
      

  4.   

    用stringlist吧
    var
      Form1: TForm1;
      Zpath:Tstringlist;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
    Zpath:=Tstringlist.Create;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
    zpath.Add('aaa');
    end;end.
      

  5.   

    var
      Zpath: TStrings;
    begin
      Zpath := TstringList.Create;
      Zpath.Add('aaa');
      zpath.free;//用完了以后释放
    end;
      

  6.   

    Zpath:TStrings;
    这一句表示Zpath是TStrings类型的变量,
    但是TStrings是一个抽象类,它是不能创建
    抽象类的实例的,必须创建TStrings的子类
    TstringList来使用。
    用完之后记得freed掉!
      

  7.   

    解决了将Zpath := TstringList.Create;
    又学到很多东西,谢谢大家了!