运算符IS与TFormClass

Edu*_*llo 6 delphi tform delphi-10.3-rio

我有以下情况:

TMyFormClass = class of TMyForm

function IsMyClass(AClass: TFormClass);
begin
  Result := AClass is TMyForm      // Operator not applicable to this operand type
  Result := AClass is TMyFormClass // Operator not applicable to this operand type
end;
Run Code Online (Sandbox Code Playgroud)

这两行都没有建立,错误是运算符不适用于此操作数类型

我该如何比较?

Dav*_*nan 10

is运算符的lhs 应该是一个实例,但是您已经提供了一个类。

您需要的是InheritsFrom类方法:

AClass.InheritsFrom(TMyForm);
Run Code Online (Sandbox Code Playgroud)