views:

157

answers:

1

I have a procedure that accepts 2 string parameters, one of them has a default value. Inside the procedure, I want to concatenate one and the other and some literals to form one larger string. Somehow, I'm getting an AV... any ideas?

code is something like this

{$WRITEABLECONST ON}
constructor MyClass.Create(s1: string; s2: string = GlobalConstant);
var s3: string;
begin
    ....
    if (s2 = '') then s2 := GlobalConstant + ' (' + s1 + ')';      // AV here
    ....
end;

If I assign GlobalConstant + ' (' + s1 + ') to s3, then assign s3 to s2 the AV disappears. Why? What is wrong with writing to the string parameter directly?

+6  A: 

Something else in your code is wrong, indirectly resulting in an Access Violation in that location (corruption). Use FastMM with FullDebugMode on to figure out what it is, and how to solve it.

Paul-Jan
@Paul-Jan, Thank you, sounds plausible to me. I'll give that a try and report back tomorrow.
Sam
I've read that page you provided the link for, and the 2 that it recommends as well. I'm using FastMM4, enabled FullDebugMode (by using the FastMM4OptionsInterface GUI), UseDebugDCUs, Stack Frames, Local Symbols, Reference Info... rebuilt Project and ran, but I don't get a log file (or maybe I can't find it!) or any MessageBoxes. I still get an AV, but now the code breaks inside class function TObject.InheritsFrom(AClass: TClass): Boolean; in WIN32\RTL\SYS\System.pas... :-) I had a full head of hair yesterday, it'll be all gone by tomorrow!
Sam
Oops, forgot to create a .map file! Project Options - Linker - Detailed Map file. (Come-on, feel sorry for the newbie.)
Sam
I downloaded the latest version of madExcept, and it works like a charm. I want to say "better than FastMM" but they're both good tools, but I found madExcept easier and more user-friendly. Anyway, the code was referencing an object that hadn't been initialised. It's weird how the AV appeared in different places though... Thanks.
Sam