* Add IsInstanceOf

This commit is contained in:
Michaël Van Canneyt 2023-11-09 11:28:53 +01:00
parent 972b961f2b
commit a9ff6272f6

View File

@ -229,6 +229,7 @@ type
function GetArrayElement(AIndex: SizeInt): TValue;
procedure SetArrayElement(AIndex: SizeInt; constref AValue: TValue);
function IsType(aTypeInfo: PTypeInfo): boolean; inline;
function IsInstanceOf(aClass : TClass): boolean; inline;
function TryCast(aTypeInfo: PTypeInfo; out aResult: TValue; const aEmptyAsAnyType: Boolean = True): Boolean;
function Cast(aTypeInfo: PTypeInfo; const aEmptyAsAnyType: Boolean = True): TValue; overload;
{$ifndef NoGenericMethods}
@ -1844,6 +1845,19 @@ begin
Result:=IsDateTimeType(TypeInfo);
end;
function TValue.IsInstanceOf(aClass : TClass): boolean;
var
Obj : TObject;
begin
Result:=IsObject;
if not Result then
exit;
Obj:=AsObject;
Result:=Assigned(Obj) and Obj.InheritsFrom(aClass);
end;
{$ifndef NoGenericMethods}
generic function TValue.IsType<T>:Boolean;
begin