Page 1 of 1
TeeGrid/TStringsData missing LoadFromCSV ???
Posted: Wed Jul 14, 2021 10:50 am
by 16591316
I am using TeeGrid, and TStringsData. I would like to read a CSV file. Is there a function or procedure in teeGrid or TStringsData that provides this? I have scanned through the documentation and source code and did not see any. Most commercial grids like TMS's TAdvStringGrid have a LoadFromCSV function to facilitate this important feature.
I have searched but did not find a similar function in TeeGrid to TStringsData.
In another forum post I saw, Teechart support says to read the CSV manually. Building a robust CSV reader can be complicated. I would prefer something of production-grade and supported by TeeGrid/TeeChart since reading in CSV (tab and delimited files) files are very common.
I know TeeBi have a CSV import function:
http://www.teechart.net/docs/teebi/tuto ... -CSV-data/
but I am not using TeeBI as it seems to be no longer developed.
What would be the recommended option?
Thanks!
Re: TeeGrid/TStringsData missing LoadFromCSV ???
Posted: Thu Jul 15, 2021 7:00 am
by 18689076
Just to agree with beowulf68, the ability to quickly read-in large CSV-files
(with the ability to specify a separator other than comma too) would be really neat.
Was also a user of the grid you mention but switched to TeeGrid due to
the exorbitant pricing and other reasons.
.
regards, Sami.
Re: TeeGrid/TStringsData missing LoadFromCSV ???
Posted: Thu Jul 15, 2021 7:46 am
by 16591316
Thanks Jonsafi!
I am switching to TeeGrid due to performance.
I tried loading 284K lines and 35 columns dataset (standard credit card fraud dataset for machine learning). The performance is like 2 secs load for TeeGrid vs 10s of seconds for standard TStringGrid and others...
I used the excellent CSV library from Vladimir Nikitenko - Delphi CSV File and String Reader Classes
https://www.codeproject.com/tips/783493 ... er-classes
I "read the CSV manually" into a TStringsData and then assigned it to TeeGrid.Data
Super fast!
It would however be great if TeeGrid and TStringsData can have a native CSV reader. Given the performance of TeeGrid, I am confident the performance will be just as fantastic.
Re: TeeGrid/TStringsData missing LoadFromCSV ???
Posted: Thu Jul 15, 2021 1:35 pm
by 18689076
Thanks for the CSV tip, Beowulf68! To read in a large CSV-file
(so-called Harvard flight dataset, several GBs),
and to display it on a grid based on TVirtualModeData,
I first read the file into a memory structure (TStringList).
Then at the OnGetCellData event, parsed the
TStringList and assigned each field to
the column/row variables for OnGetCellData .
If the CSV were integrated at the component level,
it would be blazing fast as you point out!
Re: TeeGrid/TStringsData missing LoadFromCSV ???
Posted: Fri Jul 16, 2021 2:45 am
by 16591316
Jonsafi
Why not use TStringsData instead of TStringList? I believe it does the OnGetCell for you automatically... you just need to read your CSV data into the TStringsData[Col,Row] as usual for stringgrids.
Also because it is a "matrix" structure already, you can do various manipulation like missing values, AVG, STDDEV etc which may be difficult in a TStringList structure.
Code: Select all
2) "TStringGrid" emulator with TStringsData class
Derived from TVirtualModeData, maintains an internal array of strings, one for
each cell in the grid.
Usage:
var Data : TStringsData;
Data:= TStringsData.Create; // optional params: Create(5,4)
// Set size
Data.Columns:= 5;
Data.Rows:= 4;
// Set data to grid
TeeGrid1.Data:= Data;
// Set header texts
Data.Headers[1]:='Company';
// Set cell values
Data[1,1]:= 'Steema';
}
Re: TeeGrid/TStringsData missing LoadFromCSV ???
Posted: Fri Jul 16, 2021 9:30 am
by 18689076
Indeed Beowulf68, used something very similar to your code
for displaying a smaller sized dataset, works very nicely
However, to handle huge CSV-files (even hundreds of millions of rows), I believe the
TVirtualModeData is the one to use. It does not pre-allocate the
data to my understanding, but only displays it when its turn comes
in the grid, using the event OnGetCell:
Code: Select all
Var
Data_tee_G : TVirtualModeData;
Data_tee_G := TVirtualModeData.Create(nr_cols,nr_rows,60); // just to allocate some memory
Data_tee_G.OnGetValue := AMain.GetCell; // the OnGetCell event must be fed the correct cell to show.