[fpc-devel] StrPos giving a access violation
jonas.maebe at elis.ugent.be
Mon Dec 12 11:42:15 CET 2005
On 12 dec 2005, at 08:12, Graeme Geldenhuys wrote:
>> StrPos is expecting 2 PChar params and not a Pointer.
>> Please use PChar(lFrom) and PChar(lSearch) to let the compiler
>> make the proper string to PChar conversion.
>> You never ever can cast a string to a pchar using Pointer()
> I see your point, and amended my code. Nonetheless, Delphi never
> through a AV. I see Jonas created a fix for it though.
It is very dangerous to rely on undocumented behaviour. At least the
TP documentation does not specify what happens if you pass a null
pchar to strpos, I don't know about Delphi. If you typecast an
ansistring to a pchar, then the compiler makes sure that if the
ansistring is empty (and thus a null pointer), a valid pointer to an
empty null-terminated string is returned.
More information about the fpc-devel