unit MyList;interfacetype
Node=class
no:integer;
name:string;
end;type
NodeList=class
private
nodes:array[1..100] of Node;
public
Length,Current:integer;
constructor Create;
procedure Add(nd:Node);
function FindNo(Name:string):integer;
procedure Clear();
function Next:Node;
function First:Node;
end;implementation{ NodeList }procedure NodeList.Add(nd: Node);
begin
inc(Length);
Current:=Length;
Nodes[Length]:=nd;
end;procedure NodeList.Clear;
begin Current:=0;
Length:=0
end;constructor NodeList.Create;
begin
Length:=0;
Current:=0;
end;function NodeList.FindNo(Name: string): integer;
var
i:integer;
begin
result:=-1;
for i:=1 to Length do
begin
if(Nodes[i].name=Name) then
begin
result:=Nodes[i].no;
exit;
end;
end;
end;
function NodeList.First: Node;
begin
if(Length>0) then
result:=Nodes[1];
end;function NodeList.Next: Node;
var
nd:Node;
begin
if(Length=0) then
begin
nd.no:=-1;
nd.name:='';
Result:=nd;
end;
if(Length>Current) then
begin
inc(Current);
result:=Nodes[Current];
end
else if(Length=Current) then
begin
result:=Nodes[Current];
end;
end;end.
----------
这是我编的一个类,数组列表类,但是不知道怎么使用它,在C++里面有new,那么在pascal怎么用呢?
Node=class
no:integer;
name:string;
end;type
NodeList=class
private
nodes:array[1..100] of Node;
public
Length,Current:integer;
constructor Create;
procedure Add(nd:Node);
function FindNo(Name:string):integer;
procedure Clear();
function Next:Node;
function First:Node;
end;implementation{ NodeList }procedure NodeList.Add(nd: Node);
begin
inc(Length);
Current:=Length;
Nodes[Length]:=nd;
end;procedure NodeList.Clear;
begin Current:=0;
Length:=0
end;constructor NodeList.Create;
begin
Length:=0;
Current:=0;
end;function NodeList.FindNo(Name: string): integer;
var
i:integer;
begin
result:=-1;
for i:=1 to Length do
begin
if(Nodes[i].name=Name) then
begin
result:=Nodes[i].no;
exit;
end;
end;
end;
function NodeList.First: Node;
begin
if(Length>0) then
result:=Nodes[1];
end;function NodeList.Next: Node;
var
nd:Node;
begin
if(Length=0) then
begin
nd.no:=-1;
nd.name:='';
Result:=nd;
end;
if(Length>Current) then
begin
inc(Current);
result:=Nodes[Current];
end
else if(Length=Current) then
begin
result:=Nodes[Current];
end;
end;end.
----------
这是我编的一个类,数组列表类,但是不知道怎么使用它,在C++里面有new,那么在pascal怎么用呢?
解决方案 »
- 急:遍历容器上的控件?
- 以前编译运行没有问题,不知道怎的现在总提示运行时class TstringField not found?
- 一个关于查询的简单问题.
- 高分求动态调用数据库DLL的源代码
- 加分100!!fastreport的简单问题!!!马上揭帖!
- 怎么问TImage中的图像复制到剪帖板???
- 在SQL中如何取子字符串呢?我用LEFT,LEFTSTR,LEFTBSTR都不行
- interbase数据库文件怎么连??在线等待!!
- 高手们来帮忙,关于Office文档的问题
- Delphi写的Socket客户端接收C#服务端乱码的问题
- 关于Win2K设置目录和文件所有者(SetFileSecurity)的问题!
- DBGRIDEH超难问题,给100分.
最后还要 用free 释放
不像C++中,编译器可以自动调默认构造函数。而且,因为是在堆上,所以记得用完
调用Free方法释放内存