小编Hen*_*ria的帖子

Delphi - 如果没有创建类,为什么这个函数有效?

考虑这个课程:

unit Unit2;

interface

type

  TTeste = class
  private
    texto: string;
  public
    function soma(a, b: integer): string;
  end;

implementation

procedure TForm2.Button1Click(Sender: TObject);
var
  teste: TTeste;
begin
  teste:= nil;
  teste.texto:= '';//access violation
  showmessage(teste.soma(5, 3));//no access violation
end;

{ TTeste }

function TTeste.soma(a, b: integer): string;
begin
  result:= (a+b).ToString;
end;

end.
Run Code Online (Sandbox Code Playgroud)

它真的有效吗?为什么?var崩溃了但功能没有,它是否像类功能一样工作?

delphi class function

5
推荐指数
1
解决办法
297
查看次数

标签 统计

class ×1

delphi ×1

function ×1