有几种办法:
1、如果你的数组是字符串形式的,只要从TStringList继承即可。这是一个字符串数组,并且提供了相应的函数。
2、如果你的数组想实现Delphi中某具体组件同样的功能,比如ListBox,你也可以直接继承相应的组件,如TListBox。
3、如果是任意数组,你可以用泛型容器:比如TList等。(需要Delphi2009以上的版本才支持)
4、特定的(对象)数组。就像你所提到的。比如:
type
TStudent=class(TObject)
name:String;
end;
TMyClass=Class(TObject)
student: array[0..100] of TStudent;
......
end;
......
这样,你就可以使用了:
var
myclass:TMyclass;
......
myclass.studnet[1].name:='张三';
编写示例如下:
type
TStudent = record
name: string;
age: integer;
end;
TMyclass = class
student: array[0..10] of TStudent;
procedure ShowStudent(id:Integer);
end;
procedure TMyclass.ShowStudent(id: Integer);
begin
ShowMessage(Format('姓名:%s 年龄:%d',[Self.student[id].name,Self.student[id].age]));
end;
procedure TForm2.Button5Click(Sender: TObject);
var
my: TMyclass;
begin
my := TMyclass.Create;
my.student[0].name := '张三';
my.student[0].age := 20;
my.ShowStudent(0);
end;
type
TCar=class
private
FLines: TStrings;
potected
procedure SetLines(Value: TStrings);
public
property Lines: TStrings read FLines write SetLines;
end;
再自己弄一个继承类,调用属性就可以使用了。