你可以如何从一个类方法中获取类的类型?

huangapple go评论51阅读模式
英文:

how can I get the ClassType from a Class method?

问题

你可以使用 ClassName 方法来获取类的类型。以下是示例代码:

class function TSomething.MyClass: TClass;
begin
  Result := Self;
end;

希望这有所帮助。

英文:

How do I return the type of a class in a class method?

In a regular method, I can use self.ClassType, but there doesn't seem to be a class method on TObject that achieves this (although I can get the ClassName).

class function TSomething.MyClass: TClass;
begin
  //what goes here?
end;

答案1

得分: 3

In a class method the TClassType is just Self

class function TSomething.MyClass: TClass;
begin
  result := Self;
end;
英文:

In a class method the TClassType is just Self

class function TSomething.MyClass: TClass;
begin
  result := Self;
end;

huangapple
  • 本文由 发表于 2023年4月11日 05:10:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定