Forum > Beginners

Loading textfile in TMemo, saving it and reading that file in external software

(1/2) > >>

TomTom:
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:

--- Quote from: TomTom on July 13, 2022, 01:46:55 pm ---Any ideas where can be the problem?

--- End quote ---
The first thought is that you are not closing the file. But it's better to show the code.

Zvoni:
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

TomTom:
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.


--- Quote from: Zvoni on July 13, 2022, 03:14:06 pm ---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

--- End quote ---

Thausand:

--- Quote from: TomTom on July 13, 2022, 01:46:55 pm ---1) I just opened the file (loaded in TMemo) and without changing saved it to another file = Unable to read file blah blah blah.

--- End quote ---
Binary diff

Not use program like notepad for compare.


--- Quote from: TomTom on July 13, 2022, 03:53:42 pm ---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.

--- End quote ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version