Board index » cppbuilder » TIniFile & TStringList do not return \n

TIniFile & TStringList do not return \n

Hi,

my problem is: I have a ini file containing several
messages which should be displayed by
Application->MessageBox. When a message
contains "\n", MessageBox doesn't make a new line
but displays "\n".

For example:

In "C:\\initest.ini":

******

[test]

message = first line\nsecond line

******

The code that does not work:

******

TIniFile *iniFile;

TStringList *List = new TStringList();

iniFile = new TIniFile("C:\\initest.ini");

iniFile->ReadSectionValues("test", List);

Application->MessageBox("first line\nsecond line", "that works!", MB_OK);
Application->MessageBox(List->Values["message"].c_str(), "that doesn't
work!", MB_OK);

delete iniFile, List;

******

Any ideas?

Thanx

Stefan

 

Re:TIniFile & TStringList do not return \n


Quote
Stefan Meyer wrote:
> my problem is: I have a ini file containing several
> messages which should be displayed by
> Application->MessageBox.

Please show us the 'test' part of the inifile.

Quote
> Application->MessageBox(List->Values["message"].c_str(), "that doesn't
> work!", MB_OK);

What does not work ?  You will see something is it ?

Hans.

Re:TIniFile & TStringList do not return \n


Quote
"Hans Galema" <j.m.galema.dontuset...@maartens.nl> wrote in message

news:3ee0909a$1@newsgroups.borland.com...

Quote
> Please show us the 'test' part of the inifile.

Stephan already did, it was included in his original post.

Quote
> What does not work ?  You will see something is it ?

He already explained exactly what doesn't work.

Gambit

Re:TIniFile & TStringList do not return \n


Quote
"Stefan Meyer" <even_ste...@web.de> wrote in message

news:bbq14q$c971q$1@ID-184961.news.dfncis.de...

Quote
> my problem is: I have a ini file containing several
> messages which should be displayed by
> Application->MessageBox. When a message
> contains "\n", MessageBox doesn't make a new line
> but displays "\n".

As well it should.  Your text in the file does not actually have any '\n'
character in it.  It has an "\\n" string instead.  That is, 2 separate
characters, a backslash followed by an 'n'.  That is not the same thing as a
single '\n' character.  The MessageBox is doing exactly what it is supposed
to be doing.

Since new-line characters are already reserved for use by the OS to delimit
the individual values inside the file, I would suggest that you consider
restructuring your file to be more like this instead:

    [test]
    MessageLine1=first line
    MessageLine2=second line

Then when you read the file in your code, extract the individual values and
dynamically build up the final MessageBox string, ie:

    TIniFile *iniFile = new TIniFile("C:\\initest.ini");

    AnsiString Msg, Ident;
    unsigned int idx = 0;

    while( true )
    {
        Ident = ("MessageLine" + AnsiString(++idx));
        if( !iniFile->ValueExists("test", Ident) ) break;
        if( idx != 1 ) Msg += "\n";
        Msg += iniFile->ReadString("test", Ident, "");
    }

    if( !Msg.IsEmpty() )
        Application->MessageBox(Msg.c_str(), "this should work!", MB_OK);

    delete iniFile;

Quote
> Application->MessageBox("first line\nsecond line", "that works!", MB_OK);
> Application->MessageBox(List->Values["message"].c_str(), "that doesn't
> work!", MB_OK);

That is because the second one is actualy passing "first line\\nsecond
line", not "first line\nsecond line".  See the difference?

Gambit

Re:TIniFile & TStringList do not return \n


Quote
Remy Lebeau (TeamB) wrote:
> Stephan already did, it was included in his original post.

Not for me.

Quote
> He already explained exactly what doesn't work.

Not for me.

That you see so much more in a post than I do. <g>

Hans.

Re:TIniFile & TStringList do not return \n


In Unix world  \n  means drop to the next line
In Windows/DOS, that's not the case.  Drop to the next line in DOS world is
done with \r\n.  This also applies to text files.  That's why when you open
a Unix text file in Notepad, it won't do the line breaks properly.
This also why FTP has a special transfer mode called Ascii which removes (or
adds) the \r  to text files, so you won't have those problems.

-Art

Quote
"Stefan Meyer" <even_ste...@web.de> wrote in message

news:bbq14q$c971q$1@ID-184961.news.dfncis.de...
Quote
> Hi,

> my problem is: I have a ini file containing several
> messages which should be displayed by
> Application->MessageBox. When a message
> contains "\n", MessageBox doesn't make a new line
> but displays "\n".

> For example:

> In "C:\\initest.ini":

> ******

> [test]

> message = first line\nsecond line

> ******

> The code that does not work:

> ******

> TIniFile *iniFile;

> TStringList *List = new TStringList();

> iniFile = new TIniFile("C:\\initest.ini");

> iniFile->ReadSectionValues("test", List);

> Application->MessageBox("first line\nsecond line", "that works!", MB_OK);
> Application->MessageBox(List->Values["message"].c_str(), "that doesn't
> work!", MB_OK);

> delete iniFile, List;

> ******

> Any ideas?

> Thanx

> Stefan

Re:TIniFile & TStringList do not return \n


Quote
On Fri, 6 Jun 2003 14:21:55 +0200, Stefan Meyer wrote:
>my problem is: I have a ini file containing several
>messages which should be displayed by
>Application->MessageBox. When a message
>contains "\n", MessageBox doesn't make a new line
>but displays "\n".

[snip]

Only in Unix and C runtimes does "\n" by itself mean start a new line.

The proper way is to supply a carriage return and linefeed ("\r\n").

--
 - Mike

Remove 'spambegone.net' and reverse to send e-mail.

Re:TIniFile & TStringList do not return \n


Quote
On Fri, 6 Jun 2003 12:13:10 -0600, Art Alvarado wrote:
>In Unix world  \n  means drop to the next line
>In Windows/DOS, that's not the case.  Drop to the next line in DOS world is
>done with \r\n.  This also applies to text files.  That's why when you open
>a Unix text file in Notepad, it won't do the line breaks properly.
>This also why FTP has a special transfer mode called Ascii which removes (or
>adds) the \r  to text files, so you won't have those problems.

ASCII transfer mode in FTP requires that all line end indicators be replaced
with carriage return/linefeed pairs.

That's the standard means in all Internet protocols to designate the end of a
line.

It's up to the receiving end (whether client or server) to modify the CRLF
pair to the local storage convention, which in Unix has indeed been just the
linefeed character.  I expect the original reason for getting rid of the
carriage return was some short-sighted space-saving desire.

--
 - Mike

Remove 'spambegone.net' and reverse to send e-mail.

Re:TIniFile & TStringList do not return \n


Quote
"Art Alvarado" <g...@gug.net> wrote in message

news:3ee0dc0b$2@newsgroups.borland.com...

Quote
> In Unix world  \n  means drop to the next line
> In Windows/DOS, that's not the case.

It is in the case of MessageBox(), though.  Not everything in Windows is
based on "\r\n" only.  Some things do support just "\r" or just "\n".

Gambit

Other Threads