[fpc-pascal] SetLength warnings - request
listbox at martoks-place.de
Thu Jan 10 20:23:57 CET 2019
Am 29.12.2018 um 22:35 schrieb Jonas Maebe:
> You don't need to typecast dynamic arrays to pointer to initialise them
> with nil. Simply "arr:=nil;" works. Ideally, the compiler would remove
> this extra initialisation if you add it before it got a different value,
> but it does not yet do that.
Something I just found out, while changing some old code: why does that not work?
u: UnicodeString = nil;
// Incompatible types: got "Pointer" expected "UnicodeString"
a: AnsiString = nil;
// Illegal Expression
c: TCharArray = '';
// Syntax error, "(" expected but "const string" found
Simply using '' as an initializer for Strings and nil for arrays solves it, so
it's no big deal. I'm just curious why Strings do not have the niln typeconv and
why the TCharArray can't be initialized (but assigned at runtime) with ''. And
why only the UnicodeString message actually relates what is wrong... ?
More information about the fpc-pascal