Hello guys

Hello guys,

Being HostNameLength a constant, I would love be able to declare a static array as below:
LHostName: array[0.or
LHostName: array[0..
rather than, currently:
LHostName: array[0..HostNameLength - 1] of UTF8Char;

Thanks :D

Comments

  1. assuming HostNameLength is say 200

    LHostName: array[0..LHostName: array[0..1] of UTF8Char; is correct
    LHostName: array[0..2] of UTF8Char; is correct
    LHostName: array[0..3] of UTF8Char; is correct
    ...
    LHostName: array[0..199] of UTF8Char; is correct

    ReplyDelete
  2. why not array[HostNameLength] like in C ?

    ReplyDelete
  3. I find when I am creating a static array, most of the time, I will need symbolic reference to it throughout the code, so I declare an enumerated type. That type can then be used in the array declaration, in the same way Paul TOTH suggests above.

    I realize this doesn't cover all use cases, but for me, at least, it covers most.

    In the example given, though, I have in the past done this:

    const
      HostNameLength = 200;
      HostNameLimit = HostNameLength - 1;

      LHostName: array[0..HostNameLimit] of UTF8Char;

    Apart from reducing the amount of typing needed, especially with multiple arrays of that size, you have only one length constant to maintain, and the limit is handled by the compiler.

    ReplyDelete
  4. or

    type
    HostNameRange = 0..HostNameLength-1;
    var
    LHostName: array [HostNameRange] of UTF8Char;

    ReplyDelete
  5. But - considering an UTF8Char is potentially multi-char, is it correct to say that 200 characters is the appropriate size of the buffer?

    ReplyDelete
  6. Lars Fosdal I usually go for the limit rather than the range, probably out of habit in later using it as a for loop limit. But the range is a reasonable solution, too. Since I am focused on Excel exports and ReportBuilder, I find myself using const arrays to manage columnar details, and the use of enums helps to make the coding comprehensible.

    ReplyDelete
  7. Lars Fosdal I would love to use a new syntax:
    Instead of having the minus operator, it would be possible to declare the range with upper bound exclusive, this code:
    HostNameRange = 0..HostNameLength-1;
    now, become this:
    HostNameRange = 0.
    UTF8Char is not multi-char, it is just used for interoperate with POSIX calls :D

    ReplyDelete
  8. Lars Fosdal Like some moderators. ;)

    ReplyDelete
  9. Lars Fosdal It was a joke, son, a joke. Because you are such a character. :)

    ReplyDelete
  10. Lars Fosdal I hope it will work hehehehe :D Using UTF8String to interoperate with POSIX calls looks to work nice but using UnicodeString doesn't.

    ReplyDelete
  11. Horácio Filho it's seems that the "official" way is to use System.SysUtils.TMarshaller.AsUtf8

    ReplyDelete

Post a Comment