Recent

Author Topic: Loading textfile in TMemo, saving it and reading that file in external software  (Read 366 times)

TomTom

  • Full Member
  • ***
  • Posts: 138
At work I have this software for microfilm scanner. It saves project files in XML. I need to process them because original software doesn't have some functions and I want to add them.
I need to read this file, read some values, make calculations on those values and depending on results change the line. When all is done save it.
It's easy. I'm reading the file (loading in TMemo) and saving it. But.... there is a problem and I don't know what can be wrong. The problem is that, when I save the file it can't be opened in my scanners software (Unable to read blah blah message). It's strange because original file from scaner looks exactly the same as my file.
I didn't know if it's because my modifications are wrong or there is a problem with encoding. I made some tests.

1) I just opened the file (loaded in TMemo) and without changing saved it to another file = Unable to read file blah blah blah.
2) I opened the file (TMemo) and MANUALY CHANGE some values = Unable to read file ....
3) I loaded the file into TStringList, made my modifications, saved it and it is working fine.

So there's something wrong when saving from TMemo.
I know that original file from scaner is UTF-8 file, but my files are also UTF-8 (checked in Notepad++).
Any ideas where can be the problem?



ASerge

  • Hero Member
  • *****
  • Posts: 1985
Any ideas where can be the problem?
The first thought is that you are not closing the file. But it's better to show the code.

Zvoni

  • Hero Member
  • *****
  • Posts: 1339
Weird.
The "Lines"-Property of a TMemo is a TStrings, which is the same Ancestor for TSTringList.
TStrings provides "SaveToFile", so there shouldn't be any difference between 1) and 2) compared to 3)
And yes, encoding was my first thought, but if you're sure that the encoding is correct....

btw: Have you tried opening the "new" files in other Editors? Notepad? geany? Maybe Notepad++ hides something
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

TomTom

  • Full Member
  • ***
  • Posts: 138
Now I noticed. Some of the lines (which are not important to me) are VERY LONG in original file. When I open this original file in Notepad++  there are 7 lines at the beginning of the file (not important to me). But when I Open and save this file with lazarus those lines are spread across 11 lines.  Just like somehow there is character limit per line. There is no CR/LF and the end but they're separte lines. So I guest that is the problem which I need to solve. Don't know how though.

Weird.
The "Lines"-Property of a TMemo is a TStrings, which is the same Ancestor for TSTringList.
TStrings provides "SaveToFile", so there shouldn't be any difference between 1) and 2) compared to 3)
And yes, encoding was my first thought, but if you're sure that the encoding is correct....

btw: Have you tried opening the "new" files in other Editors? Notepad? geany? Maybe Notepad++ hides something

Thausand

  • Sr. Member
  • ****
  • Posts: 291
1) I just opened the file (loaded in TMemo) and without changing saved it to another file = Unable to read file blah blah blah.
Binary diff

Not use program like notepad for compare.

Now I noticed. Some of the lines (which are not important to me) are VERY LONG in original file. When I open this original file in Notepad++  there are 7 lines at the beginning of the file (not important to me). But when I Open and save this file with lazarus those lines are spread across 11 lines.  Just like somehow there is character limit per line. There is no CR/LF and the end but they're separte lines. So I guest that is the problem which I need to solve. Don't know how though.

wordwrap: https://lazarus-ccr.sourceforge.io/docs/lcl/stdctrls/tcustommemo.wordwrap.html

Zvoni

  • Hero Member
  • *****
  • Posts: 1339
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

TomTom

  • Full Member
  • ***
  • Posts: 138
WordWrap is not the case because i always turn it off for my TMemo's.

First line that breaks is breaking after 1024 character then the rest of the line breaks after another 1029 characters and the rest of this line is in third line. So this ONE line with 2639 characters is divided into 3 lines. I think this is the limitation of TMemo because when I copy this line from original file and paste it into TMemo it's also being splitted into 3 lines.

There is no problem with SynEdit, so I'll just use that instead of TMemo.


wordwrap: https://lazarus-ccr.sourceforge.io/docs/lcl/stdctrls/tcustommemo.wordwrap.html
Yepp.
Default is True
« Last Edit: July 13, 2022, 06:21:26 pm by TomTom »

 

TinyPortal © 2005-2018