TObject = class
end;
//初始化实列
class function TObject.InitInstance(Instance: Pointer):
TObject;
{$IFDEF PUREPASCAL}
var
IntfTable: PInterfaceTable;
ClassPtr: TClass;
I: Integer;
begin
//分配需要的内存的大小
FillChar(Instance^, InstanceSize, 0);
//实列化分配好的内存
PInteger(Instance)^ := Integer(Self);
ClassPtr := Self;
//如果成功
while ClassPtr <> nil do
begin
//初始化每个接口函数的具体实现
with IntfTable.Entries[I] do
begin
end;
end;
Result := Instance;
end;
//清除实列
procedure TObject.CleanupInstance;
{$IFDEF PUREPASCAL}
var
ClassPtr: TClass;
InitTable: Pointer;
begin
//获得当前的类型
ClassPtr := ClassType;
//获得初始化标的地址
InitTable := PPointer(Integer(ClassPtr) + vmtInitTable)^;
//如果当前类存在 并且初始化表也存在
while (ClassPtr <> nil) and (InitTable <> nil) do
begin
end;
end;
//获得当前类的类型
function TObject.ClassType: TClass;
begin
//就是返回当前类的指针
Pointer(Result) := PPointer(Self)^;
end;
//获得当前类的类名
class function TObject.ClassName: ShortString;
{$IFDEF PUREPASCAL}
begin
//根据虚拟方发表返回指定的地址
Result := PShortString(PPointer(Integer(Self) +
vmtClassName)^)^;
end;
// 判断当前类的类名
class function TObject.ClassNameIs(const Name: string):
Boolean;
{$IFDEF PUREPASCAL}
var
Temp: ShortString;
I: Byte;
begin
Result := False;
//获得当前类的类名得指针
Temp := ClassName;
//根据字符串的长度比较每个字符 区分大小写
for I := 0 to Byte(Temp[0]) do
Result := True;
end;
//获得当前类的父类
class function TObject.ClassParent: TClass;
{$IFDEF PUREPASCAL}
begin
//根据虚拟方法表或的父的地址指针
Pointer(Result) := PPointer(Integer(Self) + vmtParent)^;
//如果存在父类 则返回
if Result <> nil then
end;
{$ELSE}
asm
@@exit:
end;
//获得类型信息
class function TObject.ClassInfo: Pointer;
begin
Result := PPointer(Integer(Self) + vmtTypeInfo)^;
end;
//获得实列大小
class function TObject.InstanceSize: Longint;
begin
Result := PInteger(Integer(Self) + vmtInstanceSize)^;
end;
//判断是否从一个类继承下来
class function TObject.InheritsFrom(AClass: TClass): Boolean;
{$IFDEF PUREPASCAL}
var
ClassPtr: TClass;
begin
ClassPtr := Self;
//当前类是否存在 并且和比较的类不等
while (ClassPtr <> nil) and (ClassPtr <> AClass)
do
Result := ClassPtr = AClass;
end;
{$ELSE}
asm
@@loop:
@@haveVMT:
@@success:
@@exit:
end;
//根据方法名称获得地址
class function TObject.MethodAddress(const Name: ShortString):
Pointer;
asm
@@outer:
@@haveVMT: