delphi - D2009 problems with array of char - how can I `elegantly` fix my code? -


Going through some of its old Delphi projects, upgrading them to D 2009, as I make this version a great improvement Generic.Collection - Wow !;) For all previous releases, I have to face various problems. This one I managed to solve, but the solution does not look elegant in half as I believe it can be. (Note, I have not written the Delphi code for about three years and even the back thing is that amateur hacking is not enough to understand in depth the depth of what is happening.)

< P> There will be a TFileStream in my code and read from it. The files were first written by my old Delphi app in such a way that the first three characters in the file will be valid as CTR because the file type is valid, the reader will be read in an array of characters in the first three bytes (and here's the problem, now this size (Four) is 2 bytes) and then to see this array as a string, see if it reads 'CTR'.

  var ... buffer: Sir's [0..2] sir; Start ... inStream.read (buffer, 3); If Buffer & lt; & Gt; Start 'CTR' then ShowMessage ('Not a valid file!'); Go out; End; ...  

It will compile and used to work, but now the buffer is about 6 bytes long and therefore 'CTR' is not equal to ever .

I fixed the buffer by changing the array [0..2] byte to and I started some more local variables to do the following:

The buffer for
  is s: = s + chr (b); // Notice for..in Loop is now available in D2009 if S & lt; & Gt; 'CTR' ...  

So basically I change the individual byte to a string and then compare it, but there should be a more simple way to do this. Will you put some light on this issue?

You can set your buffer

var buffer: unsecured Array of [0..2];

And you'll read in the same thing as before.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -