Jump to content


Photo

LoadFromCSV not working


  • Please log in to reply
3 replies to this topic

#1 fanki

fanki
  • Members
  • 2 posts

Posted 11 February 2025 - 04:48 PM

Hi all,

 

I'm new to NextGrid. It seems that it is rather different from StringGrid and AdvStringGrid (TMS Software) I used so far.

 

I try to load a csv file with 29 columns and 5062 rows. I get an out of bounds (-1) error when I load it with NextGrid61.Serialize.LoadFromCSV.

My code:

NextGrid61.Serialize.SeparatorChar := ';';
   NextGrid61.Serialize.Encoding := ekAnsi;
   for i := 1 to 29 do
      begin
        NextGrid61.Columns.Add(TNxNumberColumn6, 'Test', 'T');
        NextGrid61.Cells[i-1, 0] := IntToStr(i); {test to assign values to cells}
      end;
   ShowMessage('ColCount: ' + IntToStr(NextGrid61.ColCount) + ' Colums.Count: ' + IntToStr(NextGrid61.Columns.Count));
   //NextGrid61.AddRow(5062);
   NextGrid61.RowCount := 5062;
   for i := 1 to NextGrid61.RowCount do
      NextGrid61.Cells[0, i-1] := IntToStr(i);  {test to assign values to cells}
   NextGrid61.Serialize.LoadFromCSV('C:\Data\test.csv');

Isn't it possible to load a csv file without knowing number of columns and rows? If the separator is set it should be possible to load the file automatically without knowing number of columns and rows beforehand.

 

I could not find a demo project using LoadFromCSV. That suprized me because loading data from a text file into a grid seems to me a basic task.

Is there no other documentation than the user guide, "tipps and tricks" and the source code?

 

I would be glad to see an example how to use it.

 

Thanks!

 

 



#2 fanki

fanki
  • Members
  • 2 posts

Posted 12 February 2025 - 02:00 AM

Ok, over another topic I found the following link: https://help.bergsoft.net/.



#3 Boki (Berg)

Boki (Berg)

    Boki (Berg)

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

Posted 12 February 2025 - 09:15 PM

Hi,

 

Probably this topic and property may help you:

https://help.bergsof...ization/Options


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.

#4 TrevorRoberts

TrevorRoberts
  • Members
  • 15 posts

Posted 18 April 2025 - 11:46 PM

Hi, Greetings everyone!

I've checked the manuals and the topics above, but I am getting an error when I try to load from CSV.

 

I get a "List index out of bounds (-1). The TInterfaceList is empty."

 

My is my code to save to and load from a CSV file:
 

procedure TFormMain.btnSaveLinksClick(Sender: TObject);
begin
  if LinkGrid.RowCount > 0 then
  begin
    LinkGrid.Serialize.SeparatorChar := ';';
    LinkGrid.Serialize.SaveToCSV('links.csv');
  end;
end;

procedure TFormMain.btnLoadLinksClick(Sender: TObject);
begin
  If FileExists('links.csv') then
  begin
    if LinkGrid.RowCount > 0 then btnClearGridClick(Self);
    LinkGrid.BeginUpdate();
    LinkGrid.Serialize.SeparatorChar := ';';
    LinkGrid.Serialize.LoadFromCSV('links.csv');
    LinkGrid.EndUpdate();
  end;
end;

In the past Serialize.LoadFromCSV worked perfectly. Now I am using Delphi 12.1 with the latest NextGrid (nextsuite6-ext_2-25.zip).

Thanks in advance for any help.
 






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users