Wednesday, June 20, 2012

Undocumented Changes - From Delphi 2007 to Delphi XE–TRadioGroup

When I was trying  Evert Etienne's sample application for demonstrating all AnimateWindow possibilities (http://delphi.about.com/od/delphi-tips-2011/qt/hide-slide-fade-away-controls-delphi-form.htm), I noticed there was a difference of TRadioGroup in Delphi 2007 and Delphi XE(XE2).
This difference is in the below code snippet in Delphi XE:
procedure TCustomRadioGroup.ReadState(Reader: TReader);
begin
  FReading := True;
  inherited ReadState(Reader);
  FReading := False;
  if HandleAllocated then //<--- Delphi 2007 has no this checking!!!
    UpdateButtons;
end;
So, what is the deal of above difference?
The difference is, because of the checking, in Delphi XE and later version, the radio buttons will not be created until the handle of the radio group is allocated. The handle is not allocated when the radio group is just created, which means when TRadioGroup.Create is called, the buttons are not created yet. So the code like the below which is similar to  Evert Etienne’s sample will failed in Delphi XE as the controls is not nil but has no items at all:
procedure TForm1.FormCreate(Sender: TObject);
begin

TRadioButton(RadioGroup1.Controls[2]) …

end;
It is mystery to me that why it is doing that checking in Delphi XE.

No comments:

Post a Comment