Access Violation when deleting TsCheckbox

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #70162
    Alan Montgomery
    Participant

    I am getting an access violation when deleting a TsCheckBox.
    I have a dynamically generated form with TsCheckBox and an “Apply” button that is the default.
    If I click the Apply button then the form closes and the TsCheckBox is deleted without issue.
    If I press enter the Apply button’s OnClick triggers and the form closes but the TsCheckBox throws an access violation in WndProc when handling WM_KILLFOCUS or CM_EXIT.

    Tracing it though I can see the TsCheckBok.Destroy is called and deletes fCommonData and then calls the inherited Destroy which in turn calls the WndProc which then tries to update the fCommonData.

    Moving the FreeAndNil for fCommonData to after the inherited solves the problem.

    P.S. Is there a reason why you have FImageChangeLink.Free rather than FreeAndNil(FImageChangeLink) in the Destroy?

    #70171
    Support
    Keymaster

    Hello!
    Is it possible to make a demo with such dialog and where the error is repeated?

    P.S. Is there a reason why you have FImageChangeLink.Free rather than FreeAndNil(FImageChangeLink) in the Destroy?

    No reason. Do you think, FreeAndNil will be better there? Component is killed in any case there.

    #70178
    Alan Montgomery
    Participant

    Skin is Material Dark and needs to be in C:\AlphaSkins\Skins
    Run the app and press enter to get the exception.

    FreeAndNil is always better than Free – if you do end up using it later you can tell it is a nil pointer use rather than an arbitary address (or worse it works and corrupts some other object). It also means the exception is in the the deleted object not several levels down.

    Attachments:
    You must be logged in to view attached files.
    #70185
    Support
    Keymaster

    Thank you
    Could you share source files also, please?
    Can’t run Exe, unfortunately, many Bpl files are required there.

    #70188
    Alan Montgomery
    Participant

    I have attached a reworked exe and full project.
    It should now need less bpls – hopefully only Berlin ones.

    To see the issue run the exe and select the checkbox, then press enter.
    To see it work correctly click the apply button.
    They both call PopulateEditor that destroys the TsCheckBox.

    Attachments:
    You must be logged in to view attached files.
    #70198
    Support
    Keymaster

    Thank you, this error will be fixed in the nearest release.

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