분명히 다음 코드는 작동하지 않습니다비 객체 제네릭의 유형을 결정하는 방법은 무엇입니까?
....
property value: T read FTheValue;
....
function TDefiniteValue<T>.toString: string;
begin
Result:= ' definitly ';
if (value is TObject) then Result:= Result + TObject(value).ToString
else if (value is integer) then Result:= Result + IntToStr(integer(value));
// ^^^^^^^
// +++++++-- integer is not an object
end;
을 내가 아닌 객체의 유형을 비교하려면 어떻게합니까?
여기 여기,
Program Maybe;
interface
uses
System.Generics.Collections, System.SysUtils;
type
TDefiniteValue<T> = class(TEnumerable<T>)
strict private
FTheValue: T;
strict protected
function toString: string; override;
property value: T read FTheValue;
end;
implementation
function TDefiniteValue<T>.toString: string;
begin
Result:= ' definitly ';
if (value is TObject) then Result:= Result + TObject(value).ToString
else if (value is integer) then Result:= Result + IntToStr(integer(value));
// ^^^^^^^
// +++++++-- integer is not an object.
end;
begin
end.
일을하지만 필요하지 않습니다 :) –