浏览代码

* handle dyn. arrays and interfaces correctly in TypInfo.SetOrdProp

git-svn-id: trunk@30141 -
florian 10 年之前
父节点
当前提交
53d6f6bc55
共有 3 个文件被更改,包括 54 次插入1 次删除
  1. 1 0
      .gitattributes
  2. 1 1
      rtl/objpas/typinfo.pp
  3. 52 0
      tests/tbs/tb610.pp

+ 1 - 0
.gitattributes

@@ -10407,6 +10407,7 @@ tests/tbs/tb0607.pp svneol=native#text/plain
 tests/tbs/tb0608.pp svneol=native#text/pascal
 tests/tbs/tb0609.pp svneol=native#text/plain
 tests/tbs/tb205.pp svneol=native#text/plain
+tests/tbs/tb610.pp svneol=native#text/pascal
 tests/tbs/tbs0594.pp svneol=native#text/pascal
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain

+ 1 - 1
rtl/objpas/typinfo.pp

@@ -1057,7 +1057,7 @@ begin
     DataSize := 8
   else
     DataSize := 4;
-  if not(PropInfo^.PropType^.Kind in [tkInt64,tkQword,tkClass]) then
+  if not(PropInfo^.PropType^.Kind in [tkInt64,tkQword,tkClass,tkInterface,tkInterfaceRaw,tkDynArray]) then
     begin
       { cut off unnecessary stuff }
       case GetTypeData(PropInfo^.PropType)^.OrdType of

+ 52 - 0
tests/tbs/tb610.pp

@@ -0,0 +1,52 @@
+program tb;
+
+{$mode objfpc}
+{$H+}
+
+uses typinfo;
+
+{$M+}
+Type
+  TBooleanArray = Array of Boolean;
+
+  TMyObject = Class(TObject)
+  Private
+    FBooleans : TBooleanArray;
+  Published
+   Property Booleans: TBooleanArray Read FBooleans Write FBooleans;
+  end;
+
+
+Var
+  O : TMyObject;
+  P : Pointer;
+  Info : PPropInfo;
+  I : Integer;
+
+begin
+  O:=TMyObject.Create;
+  try
+    Info:=GetPropINfo(O,'Booleans');
+    // Get property using RTTI (returns Nil, as expected)
+    P:=GetObjectProp(O,Info);
+    // Clear array
+    I:=0;
+    DynArraySetLength(P,Info^.PropType,1,@i);
+    // Now, set new length
+    I:=2;
+    DynArraySetLength(P,Info^.PropType,1,@i);
+    // Set some values
+    TBooleanArray(P)[0]:=True;
+    TBooleanArray(P)[1]:=False;
+    // This is OK
+    Writeln('Length  : ',Length(TBooleanArray(P)));
+    // Set property using RTTI
+    SetObjectProp(O,Info,TObject(P));
+    // This goes wrong.
+    Writeln('Correct pointer : ',HexStr(GetObjectProp(O,Info)),' = ',HexStr(P),' ? ',Pointer(GetObjectProp(O,Info))=P);
+    // Crash !!
+    Writeln('Length array : ',Length(O.Booleans));
+  finally
+    O.Free;
+  end;
+end.