Search code examples
ipaddelphifiremonkeytgrid

Removing objects, disable horizontal scrolling on TGrid (Delphi XE5 + iPad)


Im currrently working on an iPad application which uses a TGrid with dynamic created content.

But it gives me some problems: For some reason, i cant free and release objects added to the TGrid (Removing them again). In Windows, FreeAndNil solves it, but apperently FreeAndNil does nothing in Mac Simulator or on an iPad device. The only solution i could come up with would be to set RowCount to the appropriate amount, but the controls are still present and this overwritten.

Also is it possible to disable horizontal scrolling in a TGrid somehow or would i need to implement a custom control for that?


Solution

  • On mobile platforms with ARC, Free/FreeAndNil does not immediately free an object. See The Free and DisposeOf methods under ARC.

    Instead use DisposeOf(), which immediately will call the destructor.

    DisposeOf forces the execution of the destructor code in an object. The new Delphi mobile compilers introduce a new dispose pattern implemented by calling DisposeOf, which executes the destructor code even if there are variables with pending references to the object. After the DisposeOf method is called, the object is placed in a special state, the Disposed state. This means that the destructor is not called again if DisposeOf is called again, or if the reference count reaches zero (the moment in which the memory is released).