type
TComponent1 = class(TComponent)
private
fS : array[0..5, 0..10] of string ;
function GetS(x, y: Integer): String;
procedure SetS(x, y: Integer
const Value: String);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
property s[x,y: Integer]: String read GetS write SetS;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TComponent1]);
end;
{ TComponent1 }
function TComponent1.GetS(x, y: Integer): String;
begin
if (x in [0..5]) and (y in [0..10]
then Result := fS[x, y]
else Result := '' ;
end;
procedure TComponent1.SetS(x, y: Integer
const Value: String);
begin
if (x in [0..5]) and (y in [0..10] then fS[x, y] := Value ;
end;
This example shows how to load and save an unpublished property whose value is a component that was created at runtime. It defines two methods, LoadCompProperty and StoreCompProperty that load or save the property value. The also defines an override for the DefineProperties method where these methods are passed to the streaming system. The DefineProperties method checks the filer’s Ancestor property to avoid saving a property value in inherited forms.
procedure TSampleComponent.LoadCompProperty(Reader: TReader);
begin
if Reader.ReadBoolean then
MyCompProperty := Reader.ReadComponent(nil);
end;
procedure TSampleComponent.StoreCompProperty(Writer: TWriter);
begin
Writer.WriteBoolean(MyCompProperty <> nil);
if MyCompProperty <> nil then
Writer.WriteComponent(MyCompProperty);
end;
procedure TSampleComponent.DefineProperties(Filer: TFiler);
function DoWrite: Boolean;
begin
if Filer.Ancestor <> nil then { check Ancestor for an inherited value }
begin
if TSampleComponent(Filer.Ancestor).MyCompProperty = nil then
Result := MyCompProperty <> nil
else if MyCompProperty = nil or
TSampleComponent(Filer.Ancestor).MyCompProperty.Name <> MyCompProperty.Name then
Result := True
else Result := False;
end
else { no inherited value -- check for default (nil) value }
Result := MyCompProperty <> nil;
end;
begin
inherited
{ allow base classes to define properties }
Filer.DefineProperty('MyCompProperty', LoadCompProperty, StoreCompProperty, DoWrite);
end;
}