0
votes

in Lazarus on Linux, I registered a class as a component, so that I can drop it on a form.

Works like a charm, except that the properties that I can publish are limited to simple types like strings and integers.
Whenever I try to publish a property like a TStringList or a TImage, it raises an 'Access Violation' when I click on it in the object inspector.

I compared my code with the standard components, but I can't see what they're doing differently.

So what are the additional steps necessary to use such properties in the object inspector?

2

2 Answers

2
votes

To pulish a class property you need to: 1. Create that property inside your component contructor - so it will never be nil 2. in your property Setter you need to assign from new value to your component. So you must implement Assign method or AssignTo in your component. e.g.

TMyComponent = class
private
  FString: TStrings;
published
  property Strings: TStrings read FStrings write SetStrings;
end;

constructor TMyComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  // always create it in the constructor so it will not be nil
  FStrings := TStringList.Create;
end;

procedure TMyComponent.SetStrings(const AValue: TStrings);
begin
  // this is correct statement
  FStrings.Assign(AValue);
  // this is not correct
  // FStrings := AValue;
end;
0
votes

I think this is about the same as in Delphi, for complex types to be used designtime there needs to be designtime code that handles showing/editing them.