unit TypeInfoClasses;
interface
uses
Classes, Sysutils, TypInfo, rttifunctions_u, classes_u;
type
//Stringtyp entweder hier konkret anpassen oder bedingt compilieren,
//um bedarfsgerechten Stringtyp zu erhalten
TStringType =
String;
TClassTypeInfo =
class(TPersistent)
private
FTypeKind: TTypeKind;
FTypeName: TStringType;
FMethodName: TStringType;
FMethodKind: TMethodKind;
//auch TTypeKind
FProperties: TStrings;
function GetObject: TPersistent;
function GetTypeKind(
Index: Integer): TTypeKind;
function GetTypeName(
Index: Integer): TStringType;
function GetPropertyByIndex(
Index: Integer): TStringType;
function GetPropertyByName(
Name: TStringType): TStringType;
procedure SetObject(AObject: TPersistent);
public
constructor Create;
constructor CreateForClass(AClass: TPersistent);
destructor Destroy;
override;
function ItsName(AName: TStringType): Integer;
property forObject: TPersistent
read GetObject
write SetObject;
property MethodKind: TMethodKind
read FMethodKind;
property MethodName: TStringType
read FMethodName;
property PropertyTypeName[
Index: Integer]: TStringType
read GetTypeName;
property PropertyTypeKind[
Index: Integer]: TTypeKind
read GetTypeKind;
property PropertyByIndex[
Index: Integer]: TStringType
read GetPropertyByIndex;
property PropertyByName[
Name: TStringType]: TStringType
read GetPropertyByName;
end;
implementation
function TClassTypeInfo.GetObject: TPersistent;
begin
end;
function TClassTypeInfo.GetTypeKind(
Index: Integer): TTypeKind;
begin
Result := TTypeObject(FProperties.Objects[
Index]).PropKind;
end;
function TClassTypeInfo.GetTypeName(
Index: Integer): TStringType;
begin
Result := TTypeObject(FProperties.Objects[
Index]).TypeName;
end;
function TClassTypeInfo.GetPropertyByIndex(
Index: Integer): TStringType;
begin
Result := FProperties[
Index];
end;
function TClassTypeInfo.GetPropertyByName(
Name: TStringType): TStringType;
begin
Result := FProperties[FProperties.IndexOf(
Name)];
end;
procedure TClassTypeInfo.SetObject(AObject: TPersistent);
begin
GetComponentProps(AObject.ClassName, FProperties, true);
end;
constructor TClassTypeInfo.Create;
begin
inherited Create;
FProperties := TStringList.Create;
end;
constructor TClassTypeInfo.CreateForClass(AClass: TPersistent);
begin
inherited Create;
FProperties := TStringList.Create;
GetComponentProps(AClass.ClassName, FProperties, true);
end;
destructor TClassTypeInfo.Destroy;
begin
FProperties.Free;
inherited Destroy;
end;
function TClassTypeInfo.ItsName(AName: TStringType): Integer;
var Index: Integer;
begin
Result := FProperties.IndexOf(AName);
end;
end.