Delphi - 在类定义中使用TStringList(非常新)

时间:2013-11-03 19:33:46

标签: delphi class tstringlist uses

我在Delphi中做了一个简单的类定义,我想在类和&中使用TStringList。它是构造函数(因此每次创建一个对象时,都会传递一个StringList,它会对StringList数据执行一些神奇的操作,将字符串列表复制到它自己的内部字符串列表中。我得到的问题是,当我尝试在类定义之前声明它“使用”时(因此它知道如何处理TStringList),它在编译时失败。但没有它,它不知道TStringList是什么。所以这似乎是一个范围问题。

下面是一个(非常简化的)类定义,类似于我想要做的。有人可以建议我如何使这项工作得到确定吗?

我也尝试在项目级别添加uses语句,但它仍然失败。我想知道我需要做些什么才能做到这一点。

unit Unit_ListManager;

interface

type
TListManager = Class

private
  lmList   : TStringList;
  procedure SetList;


published
  constructor Create(AList : TStringList);
end;

implementation

uses
  SysUtils,
  StrUtils,
  Vcl.Dialogs;

  constructor TBOMManager.Create(AList : TStringList);
  begin
    lmList := TStringList.Create;
    lmList := AListList;
  end;

  procedure SetPartsList(AList : TStringList);
  begin
     lmList := AListList;
     ShowMessage('Woo hoo, got here...');
  end;
end.

亲切的问候

1 个答案:

答案 0 :(得分:1)

您没有显示您添加单位参考的确切位置,但我认为这是错误的地方。请注意interfacetype之间的其他代码。

我还更正了constructor的定义,published代替publicproperty。只有published项属于unit Unit_ListManager; interface uses Classes, SysUtils, StrUtils, Vcl.Dialogs; type TListManager = Class private lmList : TStringList; procedure SetList; public constructor Create(AList : TStringList); end; implementation constructor TListManager.Create(AList : TStringList); begin inherited Create; // This way, if the parent class changes, we're covered! // lmList := TStringList.Create; This would produce a memory leak! lmList := AListList; end; procedure TListManager.SetList; begin // You never provided an implementation for this method end; end. 部分。

{{1}}
相关问题