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
Being HostNameLength a constant, I would love be able to declare a static array as below:
LHostName: array[0.
LHostName: array[0..
rather than, currently:
LHostName: array[0..HostNameLength - 1] of UTF8Char;
Thanks :D
assuming HostNameLength is say 200
ReplyDeleteLHostName: 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
why not array[HostNameLength] like in C ?
ReplyDeleteI 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.
ReplyDeleteI 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.
or
ReplyDeletetype
HostNameRange = 0..HostNameLength-1;
var
LHostName: array [HostNameRange] of UTF8Char;
But - considering an UTF8Char is potentially multi-char, is it correct to say that 200 characters is the appropriate size of the buffer?
ReplyDeleteLars 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.
ReplyDeleteLars Fosdal I would love to use a new syntax:
ReplyDeleteInstead 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
UTF8 is by definition multichar.
ReplyDeleteLars Fosdal Like some moderators. ;)
ReplyDeleteBill Meyer ?
ReplyDeleteLars Fosdal It was a joke, son, a joke. Because you are such a character. :)
ReplyDeleteLars Fosdal I hope it will work hehehehe :D Using UTF8String to interoperate with POSIX calls looks to work nice but using UnicodeString doesn't.
ReplyDeleteHorácio Filho it's seems that the "official" way is to use System.SysUtils.TMarshaller.AsUtf8
ReplyDelete