1

We are in the process of moving a number of Delphi applications to web based, and in the interim some applications are running in both.

We have a situation where the web application can correctly read line breaks written by the Delphi application, but the Delphi application ignores the line breaks when the text is saved in the web application.

As far as I can tell the Delphi application writes #$D#$A at the end of any line. In the database table these are seen as CR LF.

When the Web application saves the save block of text the line breaks become #$A when read by Delphi. In the database these still appear to be CR LF

Thoughts?

Dan Kelly
  • 2,634
  • 5
  • 41
  • 61
  • Previous XML related comment might not apply. But this [answer](https://stackoverflow.com/a/14217315/8216190) addresses HTML specifications. – nil Sep 27 '18 at 10:22
  • #$A (or #10, ^J) is the end-of-line code used in Linux and other OSes. You will have to convert. See the code of my little tool *eolconv*: https://github.com/rvelthuis/CommandLineTools/blob/master/eolconv.dpr . – Rudy Velthuis Sep 27 '18 at 10:56
  • 2
    I don't know what "the database" is in this case, but I've had an issue with Oracle and PL/SQL developer, where the linebreaks in the database were actually unix line breaks (LF, $A, \n, whichever representation you like), but the database tool translated this to the client it was running on (Windows), so it showed them as CR LF. Delphi didn't do this magic translation and actually read them as just LF. Anyway, you either have to store it consistently or convert it when you read it back from the database. In Delphi you may use the function `AdjustLineBreaks` for that conversion. – GolezTrol Sep 27 '18 at 11:35
  • Database in this case is MySQL. I'd assumed (maybe incorrectly) that as the raw data there was showing CR/LF that both Delphi and the web application were writing #13#10 to it. It may well be the client getting in the way here. – Dan Kelly Sep 27 '18 at 12:12
  • @GolezTrol That's is indeed the problem. Can you switch your comment over to an answer so I can accept it. I also didn't know about `AdjustLineBreaks` – Dan Kelly Sep 27 '18 at 12:17

1 Answers1

2

You say "the database shows", but it might actually be the tool you're using to check this database. I've had an issue with Oracle and PL/SQL developer, where the linebreaks in the database were actually unix line breaks (just linefeed, LF, $A, \n, whichever representation you like), but the database tool translated this to the client it was running on (Windows), so it showed them as CR LF. Your tool may also do this.

Delphi doesn't do this magic translation and actually read them as just LF.

So, to get a specific kind of linebreaks, you either have to store the values consistently or convert it on the fly when you read it back from the database.

In Delphi you can use the function AdjustLineBreaks for that conversion, either before saving or after fetching (or both).

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • Just for completions sake it is worth noting that MySQL Workbench on Windows appears to convert Linux line breaks to `CR/LF` pairs. This lead me to believe that the problem was something other than the line endings. – Dan Kelly Sep 28 '18 at 08:43