Cannot access component property within a TFramebar

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #34165
    mol
    Participant

    Please see the attached demo.

    Test 1:

    Click on Item 1, check the sCheckbox, click on 'Test' button -> Message is correctly displayed

    Test 2:

    Restart program and click on the 'Test' button -> Access violation


    How can I get at the checked state of sCheckbox1, if Item 1 is not expanded?

    {…}

    private

    FFrame: TFrame;

    {…}

    if TFrame2(FFrame).sCheckbox1.Checked then

    doesn't work either.

    #44097
    Support
    Keymaster

    Hello and thank you for the demo.

    The error occurs because frame is not created – frame is created immediately before opening.

    You can add such line in your code : if sFrameBar1.Items[0].Frame <> nil then …

    #44112
    mol
    Participant
    'Support' wrote:

    The error occurs because frame is not created – frame is created immediately before opening.

    Yeah, I know. Is there a way to prevent the destruction of the attached frame when I close (click on) an item?

    #44116
    mol
    Participant

    Okay, I found it: CanDestroy. Can I leave both procedures below as they are or do I need to test for sFrameBar1.Items[0].Frame <> nil and then explicitely free the frame? There do not seem to be any memory leaks if I don't, but I want to make sure that it doesn't have any other implications when CanDestroy is set to false. Thanks.

    procedure TForm1.sFrameBar1Items0CreateFrame(Sender: TObject;

    var Frame: TCustomFrame);

    begin

    Frame := TFrame1.Create(nil); // <


    do I have to check if the frame already exists before I create it?

    end;

    procedure TForm1.sFrameBar1Items0FrameDestroy(Sender: TObject;

    var Frame: TCustomFrame; var CanDestroy: Boolean);

    begin

    CanDestroy := False;

    end;

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