用一个属性存储一个动态数组

 用一个属性存储一个动态数组,可是弄了半天就是存不下来,
象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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值