Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are not overriding the constructor of <code>TCollection</code>, so <code>TCollection.Add()</code> cannot call your constructor. That is why you needed to have <code>Add()</code> set the default values.</p> <p>Even then, you are setting default property values during construction, but you are not specifying those same default values in your property declarations. You need to do so for DFM streaming to work correctly.</p> <p>You should also use <code>TOwnedCollection</code> instead of using <code>TCollection</code> directly. Let <code>TOwnedCollection</code> manage the Owner for you.</p> <p>Try this:</p> <pre><code>unit JDGrids; interface uses Classes, Windows, SysUtils, Grids, StrUtils; type TJDGridCol = class; TJDGridCols = class(TOwnedCollection) private fOnEvent: TNotifyEvent; private procedure DoEvent; property OnEvent: TNotifyEvent read fOnEvent write fOnEvent; protected function GetItem(Index: Integer): TJDGridCol; procedure SetItem(Index: Integer; Value: TJDGridCol); public constructor Create(AOwner: TComponent); reintroduce; destructor Destroy; override; function Add: TJDGridCol; reintroduce; procedure Assign(Source: TPersistent); override; procedure Clear; reintroduce; procedure Delete(Index: Integer); reintroduce; property Items[Index: Integer]: TJDGridCol read GetItem write SetItem; default; end; TJDGridCol = class(TCollectionItem) private fWidth: Integer; fTitle: String; fOnEvent: TNotifyEvent; fVisible: Bool; procedure SetTitle(const Value: String); procedure SetWidth(const Value: Integer); procedure DoEvent; procedure SetVisible(const Value: Bool); property OnEvent: TNotifyEvent read fOnEvent write fOnEvent; protected function GetDisplayName: String; override; function GetCols: TJDGridCols; function GetOwner: TComponent; public constructor Create(AOwner: TCollection); override; destructor Destroy; override; published property Title: String read fTitle write SetTitle; property Width: Integer read fWidth write SetWidth default 30; property Visible: Bool read fVisible write SetVisible default True; end; implementation { TJDGridCols } constructor TJDGridCols.Create(AOwner: TComponent); begin inherited Create(AOwner, TJDGridCol); end; destructor TJDGridCols.Destroy; begin inherited Destroy; end; function TJDGridCols.Add: TJDGridCol; begin Result := TJDGridCol(inherited Add); DoEvent; end; procedure TJDGridCols.Assign(Source: TPersistent); begin inherited Assign(Source); DoEvent; end; procedure TJDGridCols.Clear; begin inherited Clear; DoEvent; end; procedure TJDGridCols.Delete(Index: Integer); begin inherited Delete(Index); DoEvent; end; function TJDGridCols.GetItem(Index: Integer): TJDGridCol; begin Result:= TJDGridCol(inherited Items[Index]); end; procedure TJDGridCols.SetItem(Index: Integer; Value: TJDGridCol); begin inherited SetItems(Index, Value); DoEvent; end; procedure TJDGridCols.DoEvent; begin if Assigned(fOnEvent) then fOnEvent(Self); end; { TJDGridCol } constructor TJDGridCol.Create(AOwner: TCollection); begin inherited Create(AOwner); fTitle := 'Column ' + IntToStr(ID); fWidth := 30; fVisible := True; end; destructor TJDGridCol.Destroy; begin inherited Destroy; end; procedure TJDGridCol.DoEvent; begin if Assigned(fOnEvent) then fOnEvent(Self); end; function TJDGridCol.GetDisplayName: String; begin Result := fTitle; end; function TJDGridCol.GetCols: TJDGridCols; begin Result := Collection as TJDGridCols; end; function TJDGridCol.GetOwner: TComponent; begin Result := GetCols.GetOwner as TComponent; end; procedure TJDGridCol.SetTitle(const Value: String); begin if fTitle &lt;&gt; Value then begin fTitle := Value; DoEvent; end; end; procedure TJDGridCol.SetVisible(const Value: Bool); begin if fVisible &lt;&gt; Value then begin fVisible := Value; DoEvent; end; end; procedure TJDGridCol.SetWidth(const Value: Integer); begin if fWidth &lt;&gt; Value then begin fWidth := Value; DoEvent; end; end; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload