Paul Ishenin wrote:
Michael Van Canneyt wrote:
when you get to write TPersistenChild you enter the following code
tkClass:
begin
ObjValue := TObject(GetObjectProp(Instance, PropInfo));
if HasAncestor then
begin
AncestorObj := TObject(GetObjectProp(Ancestor, PropInfo));
if Assigned(AncestorObj) then
if Assigned(ObjValue) and
(TComponent(AncestorObj).Owner = FRootAncestor) and
(TComponent(ObjValue).Owner = Root) and
(UpperCase(TComponent(AncestorObj).Name) =
UpperCase(TComponent(ObjValue).Name)) then
AncestorObj := ObjValue
// else
// AncestorObj := nil;
end else
AncestorObj := nil;
--------------
TObject(GetObjectProp(Ancestor, PropInfo)); returns the
TpersistentChil
as well as ObjValue being TPersistent
both get casted to TComponent with no check?
I may have mis-judged t, but the problem is still the same:
Ancestors can only be a TComponent.
Ancestor (in this report http://bugs.freepascal.org/view.php?id=14364)
is TLabel, HasAncestor = True (since Ancestor is TLabel and
Instance.ClassType = Ancestor.ClassType) and both ObjValue and
AncestorObj are TAnchorSide (descendant of TPersistent and not
TComponent). Therefore it accessing TAnchorSide property (TPersistent)
as TComponent and we have a crash.
But maybe the problem is somewhere else. For example can Ancestor be
TLabel or it is usually some form, frame or datamodule?
and on top of that, Ancestor can be a TPersitent:
because if the AnchorSide writes it's properties, the following code,
sts ancestor to anchorside:
begin
SavedAncestor := Ancestor;
SavedPropPath := FPropPath;
try
FPropPath := FPropPath + PPropInfo(PropInfo)^.Name + '.';
if HasAncestor then
Ancestor := TPersistent(GetObjectProp(Ancestor,
PropInfo)); // <<<<<
WriteProperties(TPersistent(ObjValue));
finally
Ancestor := SavedAncestor;
FPropPath := SavedPropPath;
end;
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel