From: Phil!Gregory Date: 22:28 on 10 May 2004 Subject: Modifying Constants A minor thing, really, but I've just wasted several hours on this bug: I've been working on convincing a Delphi program to call procedures in a DLL. This is new to me, so I figure I'll do things wrong. Thus, when things go wrong, I blame myself, sometimes, as I found, needlessly: procedure SimLibLogon(pszDBName: PChar) external "EKDWS.DLL"; procedure DoStuff; var System : String; begin System := 'VADER'; SimLibLogon(PChar(System)); end; and I get an access violation. The problem? Delphi is stricter about types than C. So, with the prototype I wrote for the procedure, Delphi decides that the string is a constant, and just calls it with a pointer to wherever the program stores its string constants. The DLL was written in C. It gets a character pointer which, logically, ought to be constant, but isn't strictly so. It tries to modify it. (Consensus here is that it's probably trying to upper-case the string.) The string is in non-modifiable memory, so I get an error. I blame myself, try to fix it, and run in circles for a couple of hours. Solution? System := Format('VADER', []); Compiler has been fooled, and the string is now in modifiable memory. Sigh.
Generated at 10:28 on 16 Apr 2008 by mariachi