Recent

Author Topic: Stringgrid: saving and loading  (Read 11391 times)

w click

  • Full Member
  • ***
  • Posts: 205
Stringgrid: saving and loading
« on: December 12, 2011, 03:44:54 pm »
I've tried stringgrid1.savetofile and stringgrid1.loadfromfile and I'm creating files, but not loading tham in.  I found stringgrid1.saveoptions:=soAll; but again no joy.

Some advice please.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: Stringgrid: saving and loading
« Reply #1 on: December 12, 2011, 11:15:56 pm »
The below works for me.
Have you verified that the file location and file name are the same in both the save and load?

Code: [Select]
If FileExists(CurrentDir + PathDelim + dataFN) Then
  Begin
    Try
      sgResults.LoadFromCSVFile(CurrentDir + PathDelim + dataFN);
    Finally
    End;
  End;         

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: Stringgrid: saving and loading
« Reply #2 on: December 12, 2011, 11:21:26 pm »
And the corresponding save is ...

Code: [Select]
sgResults.SaveToCSVFile(CurrentDir + PathDelim + dataFN);   

w click

  • Full Member
  • ***
  • Posts: 205
Re: Stringgrid: saving and loading
« Reply #3 on: December 13, 2011, 10:54:23 am »
I could not get this to work, or even recognize savetocsvfile.

In the end I realised I had a spare memo on the form, so I copied all the information to that and savetofile from there, reversing to load.  It works... not very satisfying though.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: Stringgrid: saving and loading
« Reply #4 on: December 13, 2011, 02:00:04 pm »
Can you post your original code?
Also, what OS, Lazarus and fpc versions are you using?
I'm using Win32-Vista, 0.9.31-32something, 2.5.1

w click

  • Full Member
  • ***
  • Posts: 205
Re: Stringgrid: saving and loading
« Reply #5 on: December 13, 2011, 04:13:04 pm »
It's Lazarus Version 0.9.30 and Windows XP Professional Version 5.1.

It was something like:-

if fileexists('temp.dat') then stringgrid1.loadfromfile('temp.dat');

stringgrid1.savetofile('temp.dat');

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: Stringgrid: saving and loading
« Reply #6 on: December 13, 2011, 09:21:36 pm »
SaveToFile and LoadFromFile are documented here:
http://wiki.lazarus.freepascal.org/Grids_Reference_Page#Save_and_Retrieve_Grid_Content
there is even an example.

What you need to have in mind is setting SaveOptions property *before* saving or loading.

w click

  • Full Member
  • ***
  • Posts: 205
Re: Stringgrid: saving and loading
« Reply #7 on: December 15, 2011, 03:48:37 pm »
That didn't work for me.

I've reinvented some wheel and I'm using a memo as a temporary conduit.  It works fine, although clearly not the 'right way' to do it.

Thanks for the help.

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: Stringgrid: saving and loading
« Reply #8 on: December 15, 2011, 07:41:27 pm »
If you can please create a sample test project  that saves and loads a test file and include the file also. if it is a bug in grids I can try to fix it.

w click

  • Full Member
  • ***
  • Posts: 205
Re: Stringgrid: saving and loading
« Reply #9 on: January 06, 2012, 01:40:41 pm »
I finally got around to this after the festive break and created a very simple test program: it worked fine.

I'm not sure why it didn't work in the proper project, perhaps I did something stupid early on.  Having created a work around that does the job, I'm not sure I want to fiddle with it.

 

TinyPortal © 2005-2018