Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6800567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:59:07+00:00 2026-05-26T18:59:07+00:00

I’ve been fighting this crazy problem for hours and have gotten nowhere. I have

  • 0

I’ve been fighting this crazy problem for hours and have gotten nowhere. I have this problem in two completely different projects using a TCollection. When a new collection item is added, I need to initialize the values of that item. However, they’re not defaulting at all. I’m even setting them in two completely different places, in the item’s constructor, and in the collection’s add function – neither of them are working. I can set the values once the items are there, but I need to set default values. I’ve done collections in the past and never had this problem, I must be missing something here…

unit JDGrids;

interface

uses
  Classes, Windows, SysUtils, Grids, StrUtils;

type
  TJDGridCol = class;
  TJDGridCols = class;  

  TJDGridCols = class(TCollection)
  private
    fOnEvent: TNotifyEvent;
  private
    fOwner: TComponent;
    procedure DoEvent;
    property OnEvent: TNotifyEvent read fOnEvent write fOnEvent;
  protected
    function GetItem(Index: Integer): TJDGridCol;
    procedure SetItem(Index: Integer; Value: TJDGridCol);
    function GetOwner: TPersistent; override;
  public
    constructor Create(AOwner: TComponent);
    destructor Destroy; override;
    function Add: TJDGridCol;
    procedure Assign(Source: TPersistent); override;
    procedure Clear;
    procedure Delete(Index: Integer);
    property Items[Index: Integer]: TJDGridCol read GetItem write SetItem; default;
  end;

  TJDGridCol = class(TCollectionItem)
  private
    fOwner: TComponent;
    fWidth: Integer;
    fTitle: String;
    fCols: TJDGridCols;
    fOnEvent: TNotifyEvent;
    fVisible: Bool;
    procedure SetTitle(const Value: String);
    procedure SetWidth(const Value: Integer);
    procedure DoEvent;
    property OnEvent: TNotifyEvent read fOnEvent write fOnEvent;
    procedure SetVisible(const Value: Bool);
  protected
    function GetDisplayName: String; override;
  public
    constructor Create(AOwner: TJDGridCols);
    destructor Destroy; override;
  published
    property Title: String read fTitle write SetTitle;
    property Width: Integer read fWidth write SetWidth;
    property Visible: Bool read fVisible write SetVisible;
  end;

implementation

{ TJDGridCols }

constructor TJDGridCols.Create(AOwner: TComponent);
begin
  inherited Create(TJDGridCol);
  fOwner:= AOwner;
end;

destructor TJDGridCols.Destroy;
begin

  inherited Destroy;
end;

function TJDGridCols.Add: TJDGridCol;
begin
  Result:= TJDGridCol(inherited Add);
  Result.fCols:= Self;
  Result.fTitle:= 'Column '+IntToStr(Result.ID);
  Result.fWidth:= 30;
  Result.fVisible:= True;
  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;

function TJDGridCols.GetOwner: TPersistent;
begin
  Result:= fOwner;
end;

procedure TJDGridCols.SetItem(Index: Integer; Value: TJDGridCol);
begin
  inherited Items[Index]:= Value;
  DoEvent;
end;

procedure TJDGridCols.DoEvent;
begin
  if assigned(fOnEvent) then fOnEvent(Self);
end;

{ TJDGridCol }

constructor TJDGridCol.Create(AOwner: TJDGridCols);
begin
  inherited Create(AOwner);
  fOwner:= AOwner.fOwner;
  fCols:= 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;

procedure TJDGridCol.SetTitle(const Value: String);
begin
  fTitle:= Value;
  DoEvent;
end;

procedure TJDGridCol.SetVisible(const Value: Bool);
begin
  fVisible := Value;  
  DoEvent;
end;

procedure TJDGridCol.SetWidth(const Value: Integer);
begin
  fWidth := Value;
  DoEvent;
end;

end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:59:08+00:00Added an answer on May 26, 2026 at 6:59 pm

    You are not overriding the constructor of TCollection, so TCollection.Add() cannot call your constructor. That is why you needed to have Add() set the default values.

    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.

    You should also use TOwnedCollection instead of using TCollection directly. Let TOwnedCollection manage the Owner for you.

    Try this:

    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 <> Value then
      begin
        fTitle := Value;
        DoEvent;
      end;
    end;
    
    procedure TJDGridCol.SetVisible(const Value: Bool);
    begin
      if fVisible <> Value then
      begin
        fVisible := Value;  
        DoEvent;
      end;
    end;
    
    procedure TJDGridCol.SetWidth(const Value: Integer);
    begin
      if fWidth <> Value then
      begin
        fWidth := Value;
        DoEvent;
      end;
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.