[Lazarus] Access violation in SYSGETMEM_FIXED - memory corruption?

Martin lazarus at mfriebe.de
Fri May 27 11:36:56 CEST 2011


On 27/05/2011 02:07, cobines wrote:
> 2011/5/26 Martin<lazarus at mfriebe.de>:
>> Here is what happens
>> ...
> Ah, now I see. Thanks for explaining.
>
> If I think of
>    edtIconFileName.Text
> as
>    edtIconFileName.SetText(const s);
> it becomes more visible that in the trigger edtIconFileNameChange I
> cannot change what I am assigning.
At the moment: yes.

I don't csay this is correct. That depends if this "const" was placed 
there knowing and intending this (side) effect. Or if it was by 
accident. (IMHO I assume the 2nd)


> So, from what you're saying it is enough to temporarily increase
> reference count before assigning to edtIconFileName.Text. If I modify
> the code to be like this:
>
> procedure TfrmFileAssoc.btnAddNewTypeClick(Sender: TObject);
> var
>    s: String;
> begin
>    s := TExtAction(Exts.Items[0]).Icon;
>    edtIconFileName.Text:= s;
> end;
>
> there is no crash and refcount is 2 when SetText is called. And 's' is
> finalized after assignment to Text.
but be aware, if you switch the optimizer on, it may optimize this away...




More information about the Lazarus mailing list