0
votes

I have a TFrame with a TEdit component. The frames are created dynamically at runtime as a TTabsheet for a TPageControl. I need to set the TTabSheet.Caption to the TEdit.Text on the TEdits KeyPress method, but, how do I get the owner of the Frame so I can set the Caption?

procedure TKeywordFrame.KeywordNameEditKeyPress( Sender : TObject; var Key : Char );
  var
    AOwner : TComponent;

  begin
    if( ord( Key ) = VK_RETURN ) then
      begin
        AOwner := ?

        FKeywordListName := KeywordNameEdit.Text;
          with AOwner do
            begin
              Caption := KeywordNameEdit.Text;
            end;
      end;
  end;

I tried

AOwner := TKeywordFrame.Owner;

DPS.KeywordFrame.pas(272): E2233 Property 'Owner' inaccessible here

AOwner := TKeywordFrame.GetOwner();

DPS.KeywordFrame.pas(272): E2076 This form of method call only allowed for class methods or constructor

Maybe I am rummaging through the wrong haystack for a needle.

1
I gon't think that the Owner is the right choice here. Iterate the Parent until you reach the TabSheet. - Uwe Raabe
Note that you trying to access Owner/GetOwner like it would be a class method. Use Self.Owner/Self.Parent (or simply Owner/Parent) instead. - RM.
What do you pass as owner parameter to TKeywordFrame.Create ? If it is the tab sheet, go with @RM's answer. Otherwise with Uwe Raabe's answer. Don't forget that you must typecast AOwner to TTabSheet so you can access the Caption property. - dummzeuch

1 Answers

0
votes

Self.Parent was the right direction. Thanks RM.

procedure TKeywordFrame.KeywordNameEditKeyPress( Sender : TObject; var Key : Char );
  var
    AOwner : TWinControl;

  begin
    if( ord( Key ) = VK_RETURN ) then
      begin
        AOwner := Self.Parent;

        FKeywordListName := KeywordNameEdit.Text;

          if( AOwner is TTabSheet ) then
            begin
              TTabSheet( AOwner ).Caption := FKeywordListName;
            end;
      end;
  end;

It is interesting to note that Self.Parent points to TTabSheet not TFrame, as one would assume, as that is where the control resides.