在delphi中建一个类怎么这么烦,问题多多(100分)

  • 主题发起人 主题发起人 waterflow
  • 开始时间 开始时间
W

waterflow

Unregistered / Unconfirmed
GUEST, unregistred user!
想建立一个类(队列)可是问题乖乖的
代码如下:
type ReceivePoint=^TReceivePoint;
TReceivePoint=Record
Info:String; //消息内容
Next:ReceivePoint;
Pre:ReceivePoint;
End;

type
//TReceiveQueue = class
TReceiveQueue = class(TObject)
//Head,Tail:ReceivePoint;
private
{ Private declarations }
Head,Tail:ReceivePoint;
public
{ Public declarations }
constructor Create;
destructor Destroy;
Procedure Insert(InPoint:ReceivePoint);
Procedure Delete();
function GetHead():ReceivePoint;
Function GetTail():ReceivePoint;
end;

constructor TReceiveQueue.Create;
begin
//inherited Create();
//my code
New(Head);//此处报访问内存错误,受不了,难道非要控件?
//如何实现?我有点不大想看文档了
Head.Next:=nil;
Head.Pre:=nil;
Head.Info:='';
tail:=head;
end;

destructor TReceiveQueue.Destroy;
begin
//my code
Dispose(Head);
inherited Destroy();//这边有没有问题?
end;
....
 
记得有一个控件可以实现队列,栈,我给你找找阿
 
不要尝试去NEW一个带有PAS自管理类别元素的结构指针例如STRING,这样会引发DELPHI的内存
自管理出错.
TReceivePoint=Record
Info:String; //消息内容
Next:ReceivePoint;
Pre:ReceivePoint;
End;
的写法没错,但是要作为动态的东西,你最好将INFO使用动态的东西如PCHAR.
当然请记住在DISPOSE前记得把INFO也释放掉.


 
LMD 组件包里面有,可以去51Delphi.com下,LMDStackComponent,
LMDQueueComponent,LMDListComponent.
 
to minikiller
thank you very much, i will give you at least 50

有谁知道如何想c++那样比较轻松的创建一个自己的类,我是在是不想去创建什么组件
delphi不会这么恶心把,非要去创建组件,搞什么属性,我考,烦死了

 
请看以下文档:
A class method is a method (other than a constructor) that operates on classes instead of objects. The definition of a class method must begin with the reserved word class. For example,

type

TFigure = class
public
class function Supports(Operation: string): Boolean; virtual;
class procedure GetInfo(var Info: TFigureInfo); virtual;
...
end;

The defining declaration of a class method must also begin with class. For example,

class procedure TFigure.GetInfo(var Info: TFigureInfo);

begin
...
end;

 
有谁知道怎么理解这个类的类方法吗?好象很难理解

还有waterflow,刚才我忘了说DELPHI中TObject是所有其他类的最终基类,如果新类的定义中未指明基类,则新类从TOBJECT继承
 
接受答案了.
 
后退
顶部