用一个属性存储一个动态数组,可是弄了半天就是存不下来,
象ImageList,ToolBar等可以动态添加的控件是如何实现存储的,
用动态数组能实现吗?请高手指点
如果不需要在设计时赋值,可以用TList, TStringList, TObjectList存储,然后声明属性及存取方法,以字符串为例:
private
FList: TStringList;
function GetItem(index: Integer): String;
procedure SetItem(index: Integer; const Value: String);
function GetCount: Integer;
public
property Count: Integer read GetCount; // 数目
property Items[index: Integer]: String read GetItem Write SetItem;
function TForm1.GetCount: Integer;
begin
Result := FList.Count;
end;
function TForm1.GetItem(index: Integer): String;
begin
Result := FList[index];
end;
procedure TForm1.SetItem(index: Integer; const Value: String);
begin
Assert( index<=FList.Count ); // 最多为比数目大一个
if index=FList.Count then
FList.Add( Value ) // 如果比数目多一个,就增加
else
FList[index] := Value;
end;