Re: Weird string bug
From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 10/22/04
- Previous message: matt parker: "Re: damn matt parker and let him burn in hell till it freezes over"
- In reply to: Francis Burton: "Re: Weird string bug"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 22 Oct 2004 13:23:54 +0200
"Francis Burton" <fburton@nyx.net> wrote in message
news:737712375.90628@irys.nyx.net...
[...]
>> Nonetheless, AnsiStrings are not compatible with dynamic arrays of
>> Char.
> This seems to be the root of the problem. I guess I was seduced by
> the statement in Borland's printed documentation to the effect that
> conversions from "array of char" to string is handled automatically.
The term "assignment compatible" occurs several times in the
documentation. It means, more or less, that any conversions required
are implicitly supplied by the compiler. It does not mean that the
types can be treated as interchangeable. You have to allow the compiler
to detect the need for the conversion.
[...]
> I wish the docs had been more explicit on this point!
The documentation can never be exhaustive. Different people also want
different things out of it. What may be obvious to an ex-C programmer
may be hopelessly arcane to an ex-VB programmer, and the other way
around. And that's without mentioning all the different Pascal
programmers.
> I am also a little puzzled why the compiler didn't flag this
> conversion as dodgy. Was it because I explicitly used a String() cast?
Quite possibly. Casting is a dangerous business; it tells the compiler
to allow something it otherwise shouldn't. It always has the unspoken
message that you know better than the compiler. If you (suspect that you)
don't, skip the cast and pay careful attention to the error message you
get. People don't do this nearly enough; we get several questions a
month which have already been answered by the compiler error message.
> Finally, I still can't get my head round the fact that the resulting
> string appeared to be fine both in terms of content reported by the
> debugger and in term of its length reported by Length - yet when I
> assigned it to the Text property of the Edit control all hell broke
> loose. Is this easily explainable?
Perhaps it's something to do with reference counting. You did supply
the terminating NUL which was my first guess.
Groetjes,
Maarten Wiltink
- Previous message: matt parker: "Re: damn matt parker and let him burn in hell till it freezes over"
- In reply to: Francis Burton: "Re: Weird string bug"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|