Troublesome coding in TsCustomDateEdit

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #68365
    HeDiBo
    Participant

    The following code troubles me. I simply do not understand it:

    procedure TsCustomDateEdit.PopupWindowShow;
    begin
      FreeAndNil(FPopupWindow);
      if sPopupCalendar <> nil then
        sPopupCalendar.Close;
    
      FPopupWindow := TsPopupCalendar.Create(Self);
      sPopupCalendar := TForm(FPopupWindow);

    If FPopupWindow contains sPopupCalendar after FreeAndNil(FPopupWindow) sPopupCalendar points to empty space. If sPopupCalendar still contains the correct form pointer then it is overwritten in the last statement, and the memory for the form is lost (because the Close dose a Hide, not a Free).
    In other words, should the coding not be this:

    procedure TsCustomDateEdit.PopupWindowShow;
    begin
      if sPopupCalendar <> nil then
        sPopupCalendar.Close;
      FreeAndNil(FPopupWindow);
    
      FPopupWindow := TsPopupCalendar.Create(Self);
      sPopupCalendar := TForm(FPopupWindow);
    #68366
    Support
    Keymaster

    Thanks for the message, I will check this code soon.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.