On Fri, 21 May 2021, Martin Frb via fpc-devel wrote:

If you have a readonly property such as
(tested with 3.2.2 rc)

  TMyComponent = class(TComponent)
  private
    FFoo: TComponent;
  published
    property ReadOnly: TComponent read FFoo;
  end;

and FFoo is nil,
then TWriter will crash.

Is the above scenario forbidden to be implemented (and therefore the crash a result of breaking some rule)
or should that work (and the crash is a bug)?

From 3.2.2 rc sources:

procedure TWriter.WriteProperty(Instance: TPersistent; PropInfo: Pointer);
begin
  // do not stream properties without getter
  if not Assigned(PPropInfo(PropInfo)^.GetProc) then
    exit;
  // properties without setter are only allowed, if they are subcomponents
  PropType := PPropInfo(PropInfo)^.PropType;
  if not Assigned(PPropInfo(PropInfo)^.SetProc) then begin
    if PropType^.Kind<>tkClass then
      exit;
    ObjValue := TObject(GetObjectProp(Instance, PropInfo));
    if not ObjValue.InheritsFrom(TComponent) or   // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       not (csSubComponent in TComponent(ObjValue).ComponentStyle) then
      exit;
  end;

The marked line calls InheritsFrom on a nil value.

Definitely a bug. It should not crash. Please file a bugreport...

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to