Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: FMX : Label1 DisposeOf is KO with Windows 64.


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Mar 21, 2018 2:42 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Gabriel GRIPARI

Posts: 24
Registered: 3/26/09
FMX : Label1 DisposeOf is KO with Windows 64.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 21, 2018 12:18 PM
Bonjour,

Version : Embarcadero C++ Builder Entreprise 10.2.3

This FMX code works with Android 7, IOS, and Win32, but is KO under Win64 :

TLabel *MyLabel = new TLabel(this);
MyLabel->Parent = Form1;
MyLabel->Text = "Hello";
MyLabel->Position->X = 100;
MyLabel->Position->Y = 100;

MyLabel->Parent = NULL;
Form1->RemoveComponent(MyLabel);
MyLabel->DisposeOf(); <<=== Win64 : Incorrect pointer operation
delete MyLabel;

Could you help me to write the correct code for remove a TLabel from a form ?

Best regards

Gabriel
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: FMX : Label1 DisposeOf is KO with Windows 64.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 21, 2018 2:42 PM   in response to: Gabriel GRIPARI in response to: Gabriel GRIPARI
Gabriel GRIPARI wrote:

MyLabel->DisposeOf(); <<=== Win64 : Incorrect pointer operation
delete MyLabel;

DO NOT mix DisposeOf() and 'delete' together like that!

Are you sure the error is not on the 'delete' instead? This code is
performing a double-deletion on non-ARC platforms. Use EITHER 'delete'
OR DisposeOf(), but not both. 'delete' is the same as 'MyLabel = NULL'
on ARC platforms.

I would suggest an alternative approach:

#ifdef _DELPHI_AUTOREFCOUNT 
MyLabel->Parent = NULL;
MyLabel->Owner->RemoveComponent(MyLabel);
#else
delete MyLabel;
#endif
MyLabel = nullptr;


Or simply:

#ifdef _DELPHI_AUTOREFCOUNT 
MyLabel->DisposeOf();
#else
delete MyLabel;
#endif
MyLabel = nullptr;


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02