Recent

Author Topic: Stringgrid vs. LoadFromCSVFile  (Read 49981 times)

Bart

  • Hero Member
  • *****
  • Posts: 5575
    • Bart en Mariska's Webstek
Re: Stringgrid vs. LoadFromCSVFile
« Reply #45 on: August 30, 2012, 12:03:21 am »
Well, they apparently are. Stringgrids retain the line ending in the cell's string. They just don't display it.

With support I meant, it actuay shows up, otherwise one could also state TEdit supports mutiline.

Furthermore, think a bit further. If multiline were not supported, don't you think people will try to read multiline csv files anyway and complain?

Possibly...

If we woud consider doing that, then we cannot use TStringlist internally anymore, and have to design a completey different algorithm.
Doing what? Multiline support? Seems that already works.

OK, currently we load the CSV data into a TStringlist and then process each line, assuming a new line also means a new row in the context of a StringGrid.
If fields are allowed to be mutiline, this algorithm wil not do anymore.

2. Have you looked at csvdocument and its dependencies?

No I have not.
I will take a look sometime.
Mind you, if I understand the wiki correcty CsvDocument is not in LCL.
StringGrid is, and it cannot depend on external component that isn't part of LCL.

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Stringgrid vs. LoadFromCSVFile
« Reply #46 on: August 30, 2012, 12:11:57 am »
Mind you, if I understand the wiki correcty CsvDocument is not in LCL.
StringGrid is, and it cannot depend on external component that isn't part of LCL.
Perhaps you misunderstood my earlier suggestion on that:
1. Have you read what I proposed? How is that "scattered around the place"?
1.1 Use csvdocument for all csv handling in Lazarus now
1.2 Try to get csvdocument in FPC and use that when it is stable (e.g. for dataset export to csv, future perhaps import from csv)
Surely better than the current situation (custom CSV code in the actual procedure)?
2. Have you looked at csvdocument and its dependencies?

Finally, if you don't want to use csvdocument... then you'd just be trying to rewrite it to deal with all exceptions/weird formats (RFC4180, Excel) etc. I don't see any reason to do that.

As previously discussed, FPC sdf format may be shoehorned into supporting csv format. If that is the case, I'd suggest that csvdocument be in FPC and we can rewrite that, to make it seamless to the user.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Stringgrid vs. LoadFromCSVFile
« Reply #47 on: September 12, 2012, 12:06:25 pm »
In case somebody needs this: code to load a CSV file into a stringgrid using CSVDocument:
http://wiki.lazarus.freepascal.org/CsvDocument#Loading_a_csv_document_into_a_StringGrid

Improvement suggestions welcome as always...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

madepabloh

  • Full Member
  • ***
  • Posts: 160
Re: Stringgrid vs. LoadFromCSVFile
« Reply #48 on: October 07, 2012, 07:43:05 pm »
Thanks BigChimp for this nice solution.

I tried to use it, but it does not compile, because return three errors related to "MaxColCount" parameter. This is the message returned by Lazarus:
Quote
unit1.pas(125,31) Error: identifier idents no member "MaxColCount"

They are the unique errors returned.
Do you know what is the problem and how to solve it?

Thanks!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Stringgrid vs. LoadFromCSVFile
« Reply #49 on: October 07, 2012, 07:53:08 pm »
As the wiki says:
Quote
Note: this requires the development version of csvdocument (see above)

You probably didn't get the development version.

Try coping over the development version https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/csvdocument/csvdocument.pas over your existing csvdcoument.pas and try again.
(Or do it the proper way and download the entire svn version as detailed in the wiki article)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

madepabloh

  • Full Member
  • ***
  • Posts: 160
Re: Stringgrid vs. LoadFromCSVFile
« Reply #50 on: October 07, 2012, 08:15:36 pm »
Thanks BigChimp,

My fault. I downloaded both version, but only installed one... I removed the normal and installed the development version.

Now the error is different:
Quote
unit1.pas(60,3) Note: Local variable "PrevRow" not used
unit1.pas(24,15) Error: Forward declaration not solved "TForm1.LoadGridFromCSVFile(TStringGrid,AnsiString,Char="44",Boolean="TRUE",Boolean="TRUE");"
unit1.pas(8,36) Hint: Unit "math" not used in Unit1
unit1.pas(137) Fatal: There were 1 errors compiling module, stopping

The critical error now is in line 24, relared to the declaration of the procedure. I copied everything from the wiki...

EDITED:

Ok, i reply to myself. The solution is to include "TForm1." in the procedure declaration at the implementation. Solving the mistake of the example included in the wiki.
[SOLVED]
« Last Edit: October 08, 2012, 11:28:47 am by madepabloh »

madepabloh

  • Full Member
  • ***
  • Posts: 160
Re: Stringgrid vs. LoadFromCSVFile
« Reply #51 on: October 07, 2012, 08:33:35 pm »
OK, now it compiles, but it does not do what it is expected.

It has a rare visual behaviour. It does show the result into the stringgrid, except when move and click the moise on the cells. Moreover, it moves all the content of the row into one cell of the stringgrid.

I attach the test form to see if you could detect where is the problem.

Thanks!
« Last Edit: October 08, 2012, 11:55:57 am by madepabloh »

 

TinyPortal © 2005-2018