Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi all,

i have a small program written with Delphi 7.
I save a text into Ini file and then read this text from ini file with method ReadString.
However, when save text contain " or ' character, i cannot read these character.
Ex:
I save text "Comment 1" and 'Comment 2' with key 01 and key o2 at section comment
Result in ini file is:
[Comment]
01="Comment 1"
02='Comment 2'
When i read it, result is
Comment 1
Comment 2

I don't know why result text does not contain "" and '' character.
Please help me fix it.
I want result text is same with save text in ini file.

code:
Delphi
comment := IniFile.ReadString(iniSection, Format('%.02d',[index]), EmptyStr);


Thanks

What I have tried:

I don't know solution.
If you have any solution, please help me.
Posted
Updated 13-Jun-16 22:36pm
Comments
Richard MacCutchan 13-Jun-16 10:22am    
In most cases the quotes are just there to ensure that when you read the key you receive all the text, rather than just the first word. Most systems will automatically strip the quote characters before returning the data. Maybe you should check the documentation to see what it says.
Sergey Alexandrovich Kryukov 13-Jun-16 10:49am    
First of all, this is '', not "", in Delphi. You can have the string with " in the content. Now, '' is a string, empty string; it cannot be a character. "" also cannot be a character, if you are talking about the string '""'. Something is wrong in the formulation of the problem itself.

(However, I can see the problem: quotation characters are stripped...)

May I ask you why do you need these " or ' characters in the value? Do you mean that in some cases you need them, in other you don't, so you want to obtain different strings, without stripping? But then you can 1) create a work-around, 2) develop your own version of TIniFile (badly obsolete anyway, and non-standard), which is not too hard, 3) use some more robust technology, such as HTML or JSON, with fully documented and standardized behavior.

—SA
ThanhNT14 13-Jun-16 21:45pm    
Thanks for your info.
But i cannot use HTML, XML or JISON.
My program must use Ini file to save some other info.

Because comments were input by user, so i don't want to change it when save and re-load. If it is changed, user will be confused.
Sergey Alexandrovich Kryukov 13-Jun-16 22:15pm    
As I say, it's not a problem to work around this stripping. Why do you need those quotation marks, anyway?
—SA
ThanhNT14 14-Jun-16 4:36am    
My program need quotation marks.
This is request.

Please see my comment to the question.

Of course, the problem is easy to work around. But I would rather suggest an alternative idea.

Why using obsolete format which never was standardized and have serious limitations? Use some robust and standardized format, such as XML.

With Embarcadero, the solution is this: Using TXMLDocument — RAD Studio.

But I would seriously recommend to address to open source. The main source is Free Pascal. You can download all the source code and build the solution in Delphi, if you want. Please see:
fcl-xml — Lazarus wiki,
XML Tutorial — Free Pascal wiki.

Also, there is a number of 3rd-party solution. One interesting approach is the Libxml2 wrapper, which also makes SAX available: Libxml2 for pascal download | SourceForge.net[^].

And I would strongly advice to pay close attention for Free Pascal and Lazarus (IDE but also a cross-platform UI library, LCL):
Lazarus wiki,
Lazarus Homepage (includes full Free Pascal installation in its setup).

This open-source product became very strong and robust. Compared to Delphi, it's much more of a cross-platform product, perhaps the most powerful cross-platform with UI available in the worlds of programing systems producing native code, with the widest set of platforms covered.

—SA
 
Share this answer
 
Thanks all.

I had solution for this problem.
Use TMemIniFile replace TIniFile, this problem will be solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900