我上了一堂很简单的课。
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;发布于 2013-04-12 08:36:48
你创建它是错误的。
您需要将返回的对象实例存储到一个变量中,然后使用该变量(引用):
constructor TEngine.Create(TV: pSDL_Surface);
begin
Self.TV := TV;
Self.StuffClass := TStuffClass.Create;
end;现在你剩下的代码可以使用它了:
procedure TEngine.SomeOtherProcedure;
begin
Self.StuffClass.Update;
end;https://stackoverflow.com/questions/15961163
复制相似问题