开发者

Delphi: How to use line breaks in a ini file?

Is it possible to have line breaks in an ini file using Delphi?

I have a string value that I'd like to use, but it needs to have the ability for line breaks. I don't need any other formatting of the te开发者_运维问答xt.

How can I do this?


It's up to you to figure out a method to encode the line break.

Depending on the use you want to do, and the strategy you want to apply to decode it.

I use url encoding. This way I can cover a much broader range of possible values. There are many URL Decode implementations available.

Or you may follow Orjan suggestion. Or invent your own.


It's been a while since I did Delphi, but I think you can't directly include linefeeds - a line is a line.

But as Örjan says, you can include characters in your string that can be interpreted by your program as line breaks.

I doubt that "\n" is automatically treated specially in any way in a .ini file, but you could include some other rarely used character, such as the pipe (|) or tilde (~) and just let your app translate that to a line break.


I also need this when a value is stored in a TStringList. To solve this issue I have used TStringList.DelimitedText property, instead of TStringList.Text:

Define the Delimiter:

Items.StrictDelimiter:= True;
Items.Delimiter:= ';';

Save:

IniFile.WriteString('Session', 'Key', Items.DelimitedText);

Load:

Items.DelimitedText:= IniFile.ReadString('Session', 'Key', '');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜