Your output is being produced in the style of the Delphi debugger, which displays string variables using Delphi's own string-literal format. Whatever function you're using to produce that output from your own program has actually been fixed for Delphi XE. It's really your Delphi 6 output that's incorrect Delphi string literals consist of a series of printable characters between apostrophes and a series of non-printable characters designated by number signs and the numeric values of each character.To represent an apostrophe, write two of them next to each other.
The printable and non-printable series of characters can be written right not to each other; there's no need to concatenate them with the operator Here's an excerpt from the output you say is correct: $12'O)=ù'dlû'#6't There are four lone apostrophes in that string, so each one either opens or closes a series of printable characters. We don't necessarily know which is which when we start reading the string at the left because the $ 1 and 2 characters are all printable on their own. But if they represent printable characters, then the 0 ) and ù characters are in the non-printable region, and that can't be.
Therefore, the first apostrophe above opens a printable series, and the $12 part represents the character at code 18 (12 in hexadecimal). After the ù is another apostrophe. Since the previous one opened a printable string, this one must close it.
But the next character after that is d which is not and therefore cannot be the start of a non-printable character code. Therefore, this string from your Delphi 6 code is mal-formed The correct version of that excerpt is this: $12'O)=ù''dlû'#6't Now there are three lone apostrophes and one set of doubled apostrophes. The problematic apostrophe from the previous string has been doubled, indicating that it is a literal apostrophe instead of a printable-string-closing one.
The printable series continues with dlà Then it's closed to insert character No. 6, and then opened again for t The apostrophe that opens the entire string, at the beginning of the file, is implicit You haven't indicated what code you're using to produce the output you've shown, but that's where the problem was.It's not there anymore, and the code that loads the file is correct, so the only place that needs your debugging attention is any code that depended on the old, incorrect format. You'd still do well to replace your code with that of Robmil since it does better at handling (or not handling) exceptions and empty files.
Your output is being produced in the style of the Delphi debugger, which displays string variables using Delphi's own string-literal format. Whatever function you're using to produce that output from your own program has actually been fixed for Delphi XE. It's really your Delphi 6 output that's incorrect.
Delphi string literals consist of a series of printable characters between apostrophes and a series of non-printable characters designated by number signs and the numeric values of each character. To represent an apostrophe, write two of them next to each other. The printable and non-printable series of characters can be written right not to each other; there's no need to concatenate them with the + operator.
Here's an excerpt from the output you say is correct: #$12'O)=ù'dlû'#6't There are four lone apostrophes in that string, so each one either opens or closes a series of printable characters. We don't necessarily know which is which when we start reading the string at the left because the #, $, 1, and 2 characters are all printable on their own. But if they represent printable characters, then the 0, ), =, and ù characters are in the non-printable region, and that can't be.
Therefore, the first apostrophe above opens a printable series, and the #$12 part represents the character at code 18 (12 in hexadecimal). After the ù is another apostrophe. Since the previous one opened a printable string, this one must close it.
But the next character after that is d, which is not #, and therefore cannot be the start of a non-printable character code. Therefore, this string from your Delphi 6 code is mal-formed. The correct version of that excerpt is this: #$12'O)=ù''dlû'#6't Now there are three lone apostrophes and one set of doubled apostrophes.
The problematic apostrophe from the previous string has been doubled, indicating that it is a literal apostrophe instead of a printable-string-closing one. The printable series continues with dlû. Then it's closed to insert character No.6, and then opened again for t.
The apostrophe that opens the entire string, at the beginning of the file, is implicit. You haven't indicated what code you're using to produce the output you've shown, but that's where the problem was. It's not there anymore, and the code that loads the file is correct, so the only place that needs your debugging attention is any code that depended on the old, incorrect format.
You'd still do well to replace your code with that of Robmil since it does better at handling (or not handling) exceptions and empty files.
Thanks, your explanation is great. Somehow there's unintended problem with my input file so I was confused about the result. Anyway, I have done what I want to do (convert : binary file => ansistring => hex string, match the hex string with my Delphi 6 pattern).
– user May 17 at 12:12.
Actually, looking at the real data, your problem is that the file stores binary data, not string data, so interpreting this as a string is not valid at all. The only reason it works at all in Delphi 6 is that non-Unicode Delphi allows you to treat binary data and strings the same way. You cannot do this in Unicode Delphi, nor should you.
The solution to get the actual text from within the file is to read the file as binary data, and then copy any values from this binary data, one byte at a time, to a string if it is a "valid" Ansi character (printable).
I will suggest the code: function LoadFile(const FileName: TFileName): AnsiString; begin with TFileStream. Create(FileName, fmOpenRead or fmShareDenyWrite) do try SetLength(Result, Size); if Size > 0 then Read(Result1, Size); finally Free; end; end.
(Maybe you could explain the problem, too, because I don't understand what it is.) – Rob Kennedy May 16 at 6:38 1 The code still produce same invalid result like my code. – user May 16 at 6:45 Why? Because it works properly regarding exception handling.
The problem probably is in reading a non-ANSI text file. So, the Result has a non readable string? – robmil May 16 at 6:51 Just for clarify that the code doesn't produce same code with my code because your code can't read non-ANSI and there are still apostrophes in result.
– user May 16 at 7:04 1 Yes, it works correctly for handling exceptions. But what reason do you have to think that exceptions are the problem here? Non-Ansi text files don't cause exceptions.
– Rob Kennedy May 16 at 7:06.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.