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 7556667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:55:08+00:00 2026-05-30T11:55:08+00:00

I am running Lazarus 0.9.30. I have a standard TStringGrid on a form and

  • 0

I am running Lazarus 0.9.30.

I have a standard TStringGrid on a form and have a function that dynamically adds TGridColumns objects to it at run time. I have a collection of objects that contain all the attributes of each column (that I read out of a file at run time), and I want to associate each object with its corresponding column header.

I have tried the code below but at run time when I try to access the object behind the column header object, I get a ‘nil object returned. I suspect the reason this is occurring is that the grid cell (that holds the column title) is blank, and you can’t associate objects with grid cells that are empty.

type
  TTmColumnTitles = class(TTmCollection)
  public
    constructor Create;
    destructor  Destroy; override;

    function  stGetHint(anIndex : integer) : string;
  end;

type
  TTmColumnTitle = class(TTmObject)
  private
    FCaption         : string;
    FCellWidth       : integer;
    FCellHeight      : integer;
    FFontOrientation : integer;
    FLayout          : TTextLayout;
    FAlignment       : TAlignment;
    FHint            : string;

    procedure vInitialise;

  public
    property stCaption        : string      read FCaption         write FCaption;
    property iCellWidth       : integer     read FCellWidth       write FCellWidth;
    property iCellHeight      : integer     read FCellHeight      write FCellHeight;
    property iFontOrientation : integer     read FFontOrientation write FFontOrientation;
    property Layout           : TTextLayout read FLayout          write FLayout;
    property Alignment        : TAlignment  read FAlignment       write FAlignment;
    property stHint           : string      read FHint            write FHint;

    constructor Create;
    destructor  Destroy; override;
  end;

procedure TTmMainForm.vLoadGridColumnTitles
  (
  aGrid       : TStringGrid;
  aCollection : TTmColumnTitles
  );
var
  GridColumn   : TGridColumn;
  aColumnTitle : TTmColumnTitle; //Just a pointer!
  anIndex1     : integer;
  anIndex2     : integer;
begin
  for anIndex1 := 0 to aCollection.Count - 1 do
    begin
      aColumnTitle := TTmColumnTitle(aCollection.Items[anIndex1]);

      GridColumn := aGrid.Columns.Add;
      GridColumn.Width := aColumnTitle.iCellWidth;
      GridColumn.Title.Font.Orientation := aColumnTitle.iFontOrientation;
      GridColumn.Title.Layout           := aColumnTitle.Layout;
      GridColumn.Title.Alignment        := aColumnTitle.Alignment;
      GridColumn.Title.Caption          := aColumnTitle.stCaption;

      aGrid.RowHeights[0] := aColumnTitle.iCellHeight;
      aGrid.Objects[anIndex1, 0] := aColumnTitle;
    end; {for}
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-30T11:55:09+00:00Added an answer on May 30, 2026 at 11:55 am

    Just assigning an object to the Objects property isn’t enough. You have to draw the title caption from that object yourself in an OnDrawCell event handler, or assign the Cells property as well.

    and you can’t associate objects with grid cells that are empty

    Yes you can. The string and the object of one cell ‘work’ independent of each other.

    So it should be:

      for anIndex2 := 0 to aGrid.ColCount - 1 do 
      begin
        aColumnTitle := aCollection.Items[anIndex2];   // Is aCollection.Count in sync
                                                       // with aGrid.ColCount??
        aGrid.Cells[anIndex2, 0] := aColumnTitle.Caption;    
        aGrid.Objects[anIndex2, 0] := aColumnTitle;
      end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running SQL Server 2008 (not R2). I have a few reports that have URLs
I am running Lazarus 0.9.30.2. I have a TForm on which there is a
Running zookeeper 3.3.3. I have a znode that I am just trying to list,
Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
Running ActiveMQ 5.4.0. I have a group of users that subscribe and publish to
Running my script through Devel::NYTProf showed that the following portion of code took up
Running rails 3.2.3 with guard/spork/rspec/factory_girl and have the following in my spec helper: Spork.prefork
Running this query takes a long time: SELECT host,ip FROM arecords WHERE ip IN
Running an MVC web site that calls a WCF service. Site and service on
Running IIS 6 with a main website using .net 4. I have many sub

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.