Jump to content


Photo

How to access column properties created in runtime


  • Please log in to reply
2 replies to this topic

#1 qi130

qi130
  • Members
  • 20 posts

Posted 05 January 2023 - 11:10 PM

Hello !

 

In my app, I create columns in an empty grid depending on SQL definition of the queried fields

I.e char or varchar => textcolumn, numeric (int, float,...)=> Numbercolumn, etc.

GridResultat.Columns.Add(TNxNumberColumn,DC_Query.Fields.SqlName[j] );

=> the header caption is correctly set with Fields.SqlName 
 

 

I've found a bug in my app for Numbercolumn when trying to set cell content for a SQL null :

if DC_Query.Fields.IsNull[j] then
   GridResultat.Cell[j,i].AsString:='<null>'

=>

 

'<null>' is not a correct float value

 

 

Several topics in the forum refer to HideWhenEmpty and EmptyCaption properties, but I'm not able to access them in runtime

TNxNumberColumn(GridRequete.ColumnByName[DC_Query.Fields.SqlName[j]]).HideWhenEmpty:=true;

or

(GridRequete.ColumnByName[DC_Query.Fields.SqlName[j]] as TNxNumberColumn).Header.Caption    // in a MessageBox

both fire an access violation :unsure:

 

What is the correct syntax to proceed?

 

 

Thx
 

 

 



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,102 posts
  • Gender:Male

Posted 06 January 2023 - 12:31 PM

Hi,

 

Inside the numeric column you can only store numbers. <null> is still a string and can’t be set. You can set Empty property of a specific cell, or chose for example 0 to be the empty value. 
 

Here is one small example:

http://help.bergsoft.../TNxCell6/Empty


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Members Section: bms.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 qi130

qi130
  • Members
  • 20 posts

Posted 06 January 2023 - 05:05 PM

Thx Bok for your reply :)
 
I'm in progress with informations provided...
 
When I need a NumberColumn, I do the following

GridResultat.Columns.Add(TNxNumberColumn,Entete );                // "Entete" can contain SQL columnname or SQL alias ( ... as ...) if provided
GridResultat.Columns[j].Name:=DC_Query.Fields.SqlName[j];         // in runtime, no default name for NxColumn 
TNxNumberColumn(GridResultat.Columns[j]).EmptyCaption:='<null>';
TNxNumberColumn(GridResultat.Columns[j]).HideWhenEmpty:=True;

then, when processing the result of the query:

while not DC_Query.Eof do begin
   GridResultat.AddRow(1);
   i:=GridResultat.LastAddedRow;
   for j :=0 to DC_Query.Fields.FieldCount-1 do
      if DC_Query.Fields.IsNull[j] then
         if GridResultat.Columns[j] is TNxNumberColumn then GridResultat.Cell[j,i].Empty:=True
            else GridResultat.Cell[j,i].AsString:='<null>'
         else
            if DC_Query.Fields.IsBlobText[j] then ...

In debug mode, the flow is correct.

 

Unfortunatly, Cells never show <null>  for null numeric field from the query. Corresponding cells are just empty
 

I'm sure I miss something, but don't know what :unsure:

 

Any idea?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users