[Lazarus] Improper initialization of manged types

Anthony Walter sysrpl at gmail.com
Wed Jul 10 14:52:08 CEST 2013


http://cache.codebot.org/snapshops/managederror.jpg

I put a few lines to test what's going on before the error occurs and a
screenshot is provided above. WriteLn is writing out a random integer
value. I don't see any code in the assembler window to initialize the
result. In that screenshot the test is getting ready to encounter an access
violation on assignment of nil to FProp.

Result.FProp := nil; // ERROR: will occur here

The problem is this sort of thing is happening for me right now in a lot of
places, for example when I resize a dynamic array holding a TVec(N)Prop
types, or when I have a local variable.

You can actually see in that screenshot what I had tried to fix this
problem previously. That is, putting code like this as the first line in
some methods:

UIntPtr(Result.FProp) := 0;

This works somewhat, but in other places this isn't possible or is very
impractical:

procedure TList<TItem>.DeleteItem(var Item: ItemType); { virtual }
begin
  Item := default(TItem); // BOOM when TItem is TVec(n)Prop
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130710/ca8517cb/attachment-0003.html>


More information about the Lazarus mailing list