croceldon
croceldon

Reputation: 4615

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 text.

How can I do this?

Upvotes: 3

Views: 4936

Answers (3)

Cesar Romero
Cesar Romero

Reputation: 4037

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', '');

Upvotes: 3

PA.
PA.

Reputation: 29369

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.

Upvotes: 9

Carl Smotricz
Carl Smotricz

Reputation: 67800

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.

Upvotes: 6

Related Questions