Jump to content


Photo

LoadFromCSV not working


  • Please log in to reply
8 replies to this topic

#1 fanki

fanki
  • Members
  • 3 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
  • 3 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,266 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.
 



#5 Mountain

Mountain
  • Members
  • 10 posts

Posted 12 June 2025 - 11:49 PM

I came here to report the error "List index out of bounds (-1). TInterfaceList is empty." when using LoadFromCSV, and noticed there is already a topic for it. Maybe it only occurs in Delphi 12?

 

I'm attaching a demo project.

There is a "Test.csv" that I've created using the demo, but I can't load it back.

 

Demo features:

Press Insert to add rows to the grid.

Click Save to save grid content as "Test.csv" in exe-folder.

Click Open to load "Test.csv" from exe-folder.

 

 

Attached Files

  • Attached File  Test.zip   74.66KB   1 downloads


#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

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

Posted 13 June 2025 - 12:29 AM

Hi,

 

Please sorry for delay fixing this issue. I’m working on it.


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.

#7 fanki

fanki
  • Members
  • 3 posts

Posted 26 November 2025 - 02:01 AM

I could solve the problem 'List index out of bounds (-1)' by adding the following line:

NextGrid61.Serialize.Options := [soAddColumns, soSetHeaderCaptions];

but there are added the same amount of empty rows to the end of the grid as imported rows.

 

I also tried the example from Mountain (Test.zip) and added above line. But I still get the 'out of bounds' error. I used Delphi 10.2.
 



#8 Mountain

Mountain
  • Members
  • 10 posts

Posted 07 December 2025 - 02:01 PM

I noticed that the CSV file is saved as UTF16 with BOM.

If I resave the CSV file as ANSI or UTF8 without BOM, then the import works.

 

So, if you don't need unicode then you can add NxTypes6 to the unit, under uses, and set

grGroup.Serialize.Encoding := ekAnsi; //replace grGroup with the name of your TNxGrid6 component

 

And, in that case, any previously saved CSV needs to be converted to ANSI.

 

 

Seems like a problem with the support for UTF16 in LoadFromFile?



#9 Boki (Berg)

Boki (Berg)

    Boki (Berg)

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

Posted Yesterday, 02:45 PM

Hi,

 

Unfortunately I got little bit stuck with all BOM/non BOM encoding so it took little bit of time. I'm sorry again for the delay. One thing I'm sure that is not that easy to guess encoding by simple reading so I will made that parameter is required when saving/loading in UTF8.


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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users