怎么给类实例出的很多对象排序
delphi吧
全部回复
仅看楼主
level 2
我去钓鱼 楼主
假设有这样个类
Myclsaa=class
name: string;
list : integer;
end;
现在我想让dt[i]声明成Myclass的对象
就是这个效果
dt[1]:Myclass ;
dt[2]:Myclass ;
....
意思就是当Myclass的对象可以自动创建时 怎么给这些对象自动的加上排序号
要是直接声明var dt [i]:Myclass ; 报错 因为dt[i]没有被声明 但是dt[i]应该被声明成什么呢?
2014年04月19日 07点04分 1
level 9
了解一下 list.add
2014年04月19日 08点04分 2
level 12
你这语法,C不像C,Pascal不像Pascal,编译器当然看不懂.
2014年04月19日 09点04分 3
下面是代码 大神帮看看
2014年04月19日 10点04分
这个代码是错的 编译器直接不认 帮看看
2014年04月19日 10点04分
回复 我去钓鱼 :直接用数组就行了
2014年04月20日 09点04分
level 2
我去钓鱼 楼主
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
edt1: TEdit;
edt2: TEdit;
btn1: TButton;
btn2: TButton;
btn3: TButton;
procedure btn3Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Myclass=class
name:string ;
list:Int64;
end;
var
Form1: TForm1;
i:Integer ;
s:string ;
t:Integer ;
implementation
{$R *.dfm}
procedure TForm1.btn3Click(Sender: TObject);
begin
Close ;
end;
procedure TForm1.btn1Click(Sender: TObject);
dt[i]:myclass;
begin
i:=1;
s:=edt1.Text ;
t:=StrToInt(edt2.text) ;
dt[i]:=myclass.create;
dt[i].name:=s;
dt[i].list:=t;
ShowMessage(dt[i].name);
end;
end.
2014年04月19日 10点04分 4
level 13
[汗]数组没学过?别语法都不去看就乱搞。
2014年04月19日 13点04分 5
不是啊 数组只能声明成字符串 数这些类型 可以把数字声明成对象吗 dt:array of 什么呢 ?
2014年04月19日 14点04分
回复 我去钓鱼 :[汗]数组的基类型当然可以是类。
2014年04月19日 15点04分
回复 我去钓鱼 :回去重新看下书。
2014年04月19日 15点04分
嘿嘿 谢谢大神[真棒]
2014年04月19日 15点04分
1