2
votes

(Firemonkey,XE7) I have a component with TTextControl ancestor, introduced SizeConstraints, just based on the VCL version. The designer does not save the Constraint property into the .FMX file. When I look at the "view form as text" the constraint is not there, even if I edited the property values before (yes I can edit it in Object Inspector, but it's not saved) What's wrong with this code?

Constraint definition:

TSizeConstraints = class(TObject)
...
published
...
    property MaxHeight: Single index 0 read FMaxHeight write SetConstraints;
    property MaxWidth: Single index 1 read FMaxWidth write SetConstraints;
...
end;  

Component definition:

  ...
  published
    property Constraints : TSizeConstraints read FConstraints write SetConstraints;
  ...

procedure TMyComponent.SetConstraints(const Value: TSizeConstraints);
begin
  FConstraints.Assign(Value);
end;

And TSizeConstraints.Assign does copy the data:

procedure TSizeConstraints.Assign( const C : TSizeConstraints );
begin
  if Assigned( C ) then
    begin
      FMinHeight := C.FMinHeight;
      FMaxHeight := C.FMaxHeight;
      FMinWidth := C.FMinWidth;
      FMaxWidth := C.FMaxWidth;
      Change;
    end;
end;

What am I missing, or is it an IDE bug?

1

1 Answers

5
votes

The problem is that you derive from TObject. Derive this class from TComponent to get streaming capabilities. Or perhaps TPersistent as @NGLN suggests.

You should also change your Assign method to override the virtual Assign introduced in TPersistent.