* fixed SetInterfaceProp
+ PInterface
* extended trtti1

git-svn-id: trunk@10334 -
This commit is contained in:
florian 2008-02-15 20:54:10 +00:00
parent e0246fcf2c
commit c46b44b797
3 changed files with 58 additions and 13 deletions

View File

@ -112,7 +112,7 @@
clock_seq_hi_and_reserved : byte; // The high field of the clock sequence multiplexed with the variant clock_seq_hi_and_reserved : byte; // The high field of the clock sequence multiplexed with the variant
clock_seq_low : byte; // The low field of the clock sequence clock_seq_low : byte; // The low field of the clock sequence
node : array[0..5] of byte; // The spatially unique node identifier node : array[0..5] of byte; // The spatially unique node identifier
); );
end; end;
// This enumerate is found both in the rtl and compiler. Do not change the order of the fields. // This enumerate is found both in the rtl and compiler. Do not change the order of the fields.
@ -227,7 +227,7 @@
property RefCount : longint read frefcount; property RefCount : longint read frefcount;
end; end;
TInterfacedClass = class of TInterfacedObject; TInterfacedClass = class of TInterfacedObject;
TAggregatedObject = class(TObject) TAggregatedObject = class(TObject)
private private
fcontroller: Pointer; fcontroller: Pointer;
@ -243,7 +243,7 @@
end; end;
TContainedObject = class(TAggregatedObject,IInterface) TContainedObject = class(TAggregatedObject,IInterface)
protected protected
function QueryInterface(const iid : tguid;out obj) : longint;virtual; stdcall; function QueryInterface(const iid : tguid;out obj) : longint;virtual; stdcall;
end; end;
@ -252,6 +252,7 @@
PPUnknown = ^PUnknown; PPUnknown = ^PUnknown;
PDispatch = ^IDispatch; PDispatch = ^IDispatch;
PPDispatch = ^PDispatch; PPDispatch = ^PDispatch;
PInterface = PUnknown;
TExceptProc = Procedure (Obj : TObject; Addr : Pointer; FrameCount:Longint; Frame: PPointer); TExceptProc = Procedure (Obj : TObject; Addr : Pointer; FrameCount:Longint; Frame: PPointer);

View File

@ -142,7 +142,7 @@ unit typinfo;
RawIntfUnit: ShortString; RawIntfUnit: ShortString;
IIDStr: ShortString; IIDStr: ShortString;
); );
tkDynArray: tkDynArray:
( (
elSize : PtrUInt; elSize : PtrUInt;
elType2 : PPTypeInfo; elType2 : PPTypeInfo;
@ -306,9 +306,9 @@ Type
TSetPropValue = Procedure (Instance: TObject; const PropName: string; const Value: Variant); TSetPropValue = Procedure (Instance: TObject; const PropName: string; const Value: Variant);
TGetVariantProp = Function (Instance: TObject; PropInfo : PPropInfo): Variant; TGetVariantProp = Function (Instance: TObject; PropInfo : PPropInfo): Variant;
TSetVariantProp = Procedure (Instance: TObject; PropInfo : PPropInfo; const Value: Variant); TSetVariantProp = Procedure (Instance: TObject; PropInfo : PPropInfo; const Value: Variant);
EPropertyConvertError = class(Exception); // Not used (yet), but defined for compatibility. EPropertyConvertError = class(Exception); // Not used (yet), but defined for compatibility.
Const Const
OnGetPropValue : TGetPropValue = Nil; OnGetPropValue : TGetPropValue = Nil;
OnSetPropValue : TSetPropValue = Nil; OnSetPropValue : TSetPropValue = Nil;
@ -1123,13 +1123,34 @@ begin
end; end;
procedure SetInterfaceProp(Instance: TObject; PropInfo: PPropInfo; const Value: IInterface); procedure SetInterfaceProp(Instance: TObject; PropInfo: PPropInfo; const Value: IInterface);
type
TSetIntfStrProcIndex=procedure(index:longint;const i:IInterface) of object;
TSetIntfStrProc=procedure(i:IInterface) of object;
var
AMethod : TMethod;
begin begin
{$ifdef cpu64} case Propinfo^.PropType^.Kind of
SetInt64Prop(Instance,PropInfo,Int64(Value)); tkInterface:
{$else cpu64} begin
SetOrdProp(Instance,PropInfo,Integer(Value)); case (PropInfo^.PropProcs shr 2) and 3 of
{$endif cpu64} ptField:
PInterface(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
ptstatic,
ptvirtual :
begin
if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
AMethod.Code:=PropInfo^.SetProc
else
AMethod.Code:=PPointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
AMethod.Data:=Instance;
if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
TSetIntfStrProcIndex(AMethod)(PropInfo^.Index,Value)
else
TSetIntfStrProc(AMethod)(Value);
end;
end;
end;
end;
end; end;
{ --------------------------------------------------------------------- { ---------------------------------------------------------------------

View File

@ -31,6 +31,7 @@ Type
FMyEnum : TMyEnum; FMyEnum : TMyEnum;
FAnsiString : AnsiSTring; FAnsiString : AnsiSTring;
FObj : TObject; FObj : TObject;
FIntf : IInterface;
FStored : Boolean; FStored : Boolean;
Function GetBoolean : Boolean; Function GetBoolean : Boolean;
Function GetByte : Byte; Function GetByte : Byte;
@ -83,6 +84,7 @@ Type
Destructor Destroy;override; Destructor Destroy;override;
Published Published
Property ObjField: TObject read FObj write FObj; Property ObjField: TObject read FObj write FObj;
Property IntfField: IInterface read FIntf write FIntf;
Property BooleanField : Boolean Read FBoolean Write FBoolean; Property BooleanField : Boolean Read FBoolean Write FBoolean;
Property ByteField : Byte Read FByte Write FByte; Property ByteField : Byte Read FByte Write FByte;
Property CharField : Char Read FChar Write FChar; Property CharField : Char Read FChar Write FChar;
@ -137,11 +139,14 @@ begin
FExtended :=8.0; { Extended;} FExtended :=8.0; { Extended;}
FMyEnum:=methird; { TMyEnum;} FMyEnum:=methird; { TMyEnum;}
FAnsiString:='this is an AnsiString'; FAnsiString:='this is an AnsiString';
FObj:=TObject.Create;
FIntf:=TInterfacedObject.Create;
end; end;
Destructor TMyTestObject.Destroy; Destructor TMyTestObject.Destroy;
begin begin
FObj.Free;
Inherited Destroy; Inherited Destroy;
end; end;
@ -457,6 +462,7 @@ begin
Writeln (' Default : ',Default,' Index : ',Index); Writeln (' Default : ',Default,' Index : ',Index);
Writeln (' NameIndex : ',NameIndex); Writeln (' NameIndex : ',NameIndex);
end; end;
FreeMem (PP);
end; end;
Procedure PrintObject ( Obj: TMyTestObject); Procedure PrintObject ( Obj: TMyTestObject);
@ -465,6 +471,8 @@ begin
With Obj do With Obj do
begin begin
Writeln ('Field properties :'); Writeln ('Field properties :');
Writeln ('Property ObjField : ',PtrUInt(ObjField));
Writeln ('Property IntfField : ',PtrUInt(IntfField));
Writeln ('Property booleanField : ',booleanField); Writeln ('Property booleanField : ',booleanField);
Writeln ('Property ByteField : ',ByteField); Writeln ('Property ByteField : ',ByteField);
Writeln ('Property CharField : ',CharField); Writeln ('Property CharField : ',CharField);
@ -511,7 +519,7 @@ Var
I,J : Longint; I,J : Longint;
PP : PPropList; PP : PPropList;
prI : PPropInfo; prI : PPropInfo;
Intf : IInterface;
begin begin
PI:=O.ClassInfo; PI:=O.ClassInfo;
Writeln ('Type kind : ',TypeNames[PI^.Kind]); Writeln ('Type kind : ',TypeNames[PI^.Kind]);
@ -550,14 +558,28 @@ begin
flush (output); flush (output);
Write(GetStrProp(O,Pri)); Write(GetStrProp(O,Pri));
end; end;
tkInterface : begin
Write ('value : ');
flush (output);
Write(PtrUInt(GetInterfaceProp(O,Pri)));
{ play a little bit with the interface to test SetInterfaceProp }
SetInterfaceProp(O,Pri,TInterfacedObject.Create);
end;
tkClass : begin
Write ('value : ');
flush (output);
Write(PtrUInt(GetObjectProp(O,Pri)));
end;
else else
Write ('Untested type:',ord(pri^.proptype^.kind)); Write ('Untested type:',ord(pri^.proptype^.kind));
end; end;
Writeln (')'); Writeln (')');
end; end;
end; end;
FreeMem (PP);
end; end;
Var O : TMyTestObject; Var O : TMyTestObject;
begin begin
@ -565,4 +587,5 @@ begin
DumpTypeInfo(O); DumpTypeInfo(O);
PrintObject(O); PrintObject(O);
testget(o); testget(o);
O.Free;
end. end.