Jump to content


Photo

Getting column type from dataset?


  • Please log in to reply
1 reply to this topic

#1 littlebigfred

littlebigfred
  • Members
  • 176 posts

Posted 22 October 2009 - 01:54 AM

Hello

I have a couple of questions on how to go creating columns in a NextGrid from a dataset:

1. Is there a two-column list that maps NextGrid column types to compatible Delphi datatypes, eg. "TNxTextColumn = String", "TNxCheckBoxColumn = String, Boolean", "TNxNumberColumn = Integer, Double", etc.?

2. Is there a simple way to display the datatype returned by the dataset, and create a compatible column in a grid?

Here's the current code:
CODE
ASQLite3Query1.SQL.Text := 'SELECT * FROM mytable';
ASQLite3Query1.Open;

for mycol := 0 to ASQLite3Query1.FieldCount - 1 do begin
  //======== The quick way to see how wrapper maps SQLite to Delphi
  //E2250 There is no overloaded version of 'IntToStr' that can be called with these arguments
  //ShowMessage(IntToStr(ASQLite3Query1.Fields[mycol].DataType));

  //E2089 Invalid typecast
  //ShowMessage(String(ASQLite3Query1.Fields[mycol].DataType));

  //======== The longer way...
  case ASQLite3Query1.Fields[mycol].DataType of
    ftString:
      Columns.Add(TNxTextColumn,'My Col1');
    ftSmallint:
      Columns.Add(TNxNumberColumn,'My Col1');
    ftInteger:
      Columns.Add(TNxNumberColumn,'My Col1');
    ftWord:
      Columns.Add(TNxNumberColumn,'My Col1');
    etc.
  else
    ShowMessage('Other type');
  end;
end;


Thank you.

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

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

Posted 22 October 2009 - 07:56 PM

Hello Franky,

Only solution is to determine DataType (as you have done with case structure) and then set ColumnClass to desired type of column.

I suggest that you look for procedure TNextDBGrid.CreateColumns; inside NxDBGrid.pas . You will see how I have done this.

I hope that this helps smile.gif
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users