我在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.
亲切的问候
答案 0 :(得分:1)
您没有显示您添加单位参考的确切位置,但我认为这是错误的地方。请注意interface
和type
之间的其他代码。
我还更正了constructor
的定义,published
代替public
。property
。只有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}}