Pascal:在类上调用空方法
我有一门非常刻板的课Pascal:在类上调用空方法,pascal,freepascal,delphi,Pascal,Freepascal,Delphi,我有一门非常刻板的课 unit StuffClass; {$mode objfpc}{$H+} interface type TStuffClass = class public procedure Update; end; implementation procedure TStuffClass.Update; begin end; end. 创建它的一个实例,并调用它的Update过程会导致程序SIGSEGV 怎么回事。。?它什么也没做 我使用的是
unit StuffClass;
{$mode objfpc}{$H+}
interface
type
TStuffClass = class
public
procedure Update;
end;
implementation
procedure TStuffClass.Update;
begin
end;
end.
创建它的一个实例,并调用它的Update
过程会导致程序SIGSEGV
怎么回事。。?它什么也没做
我使用的是Freepascal(&Lazarus)32位版本
为什么会这样
编辑:以下是调用位:
//Creating it
constructor TEngine.Create(TV: pSDL_Surface);
begin
Self.TV := TV;
Self.StuffClass.Create;
end;
function TEngine.Update: Boolean;
begin
WriteLN('Test');
SDL_PumpEvents;
Self.StuffClass.Update; //Crashes here.
Update := True;
end;
你弄错了 您需要将返回的对象实例存储到变量中,然后改用该变量(引用): 现在,您的其余代码可以使用它:
procedure TEngine.SomeOtherProcedure;
begin
Self.StuffClass.Update;
end;
事实上,我正在这么做。
StuffClass
是另一个名为Engine
的类的私有成员。那么,不要让我们猜测您做错了什么。发布显示问题行为的实际代码。没有显示如何使用导致错误的类定义是毫无意义的。只是表明我的猜测是正确的。:-)我编辑了我的答案,以显示使用您的实际代码。感谢您的编辑。:-)嘿,谢谢。我犯了一个多么愚蠢的错误。(你也是早些时候回答我的帕斯卡哑巴问题的人,所以也谢谢你!)
procedure TEngine.SomeOtherProcedure;
begin
Self.StuffClass.Update;
end;