Hallo,
Du musst die Loaded Methode überschreiben. Die Direktive stored bewirkt lediglich, dass die property auch gespeichert wird
wenn sie den Defaultwert enthält.
Delphi-Quellcode:
TMyStringGrid = class(TStringGrid)
private
FColumnHeader: TStrings;
procedure SetColumnHeader(Value: TStrings);
procedure FillHeader;
protected
procedure Loaded; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ColumnHeader: TStrings read FColumnHeader write SetColumnHeader;
end;
constructor TMyStringGrid.Create(AOwner: TComponent);
begin
inherited create(AOwner);
FColumnHeader := TStringList.Create;
end;
destructor TMyStringGrid.Destroy;
begin
FColumnHeader.Free;
inherited destroy;
end;
procedure TMyStringGrid.SetColumnHeader(Value: TStrings);
begin
FColumnHeader.Assign(Value);
FillHeader;
end;
procedure TMyStringGrid.Loaded;
begin
inherited Loaded;
FillHeader;
end;
procedure TMyStringGrid.FillHeader;
var
iCol: integer;
begin
for iCol := 0 to ColCount - 1 do
if iCol < FColumnHeader.Count then
Cells[iCol,0] := FColumnHeader[iCol]
else
Cells[iCol,0] := '';
end;