PageControl add/update new function

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #68582
    Rafał Drzewiecki
    Participant

    Can you add this in next update AC? In this or more extensive form. This is Event OnPageChangeTab. Reacts to: Change Tab by mouse, ActivPageIndex and delete Tab.

    type
      TacTabChange      = procedure(Sender: TComponent) of object;
    
      TsPageControl = class(TPageControl)
      private
        FOnPageChangeTab: TacTabChange;
      published
        property OnPageChangeTab: TacTabChange        read FOnPageChangeTab write FOnPAgeChangeTab;  
      end;
      
    procedure TsPageControl.SetActivePage(const Value: TsTabSheet);
    begin
      if Value <> nil then begin
        inherited ActivePage := CheckActiveTab(Value.PageIndex);
        AddToAdapter(ActivePage);
        if not Value.TabVisible and not SkinData.FUpdating then
          SetParentUpdated(Value); // Update because TCM_SETCURSEL is not received
    
        //Rafal
        if Assigned(OnPageChangeTab) then
          OnPageChangeTab(Self);
      end
      else
        inherited ActivePage := nil;
    end;
    
    procedure TsPageControl.SetActivePageIndex(const Value: Integer);
    begin
      if IsValidIndex(Value, PageCount) and (TsTabSheet(Pages[Value]).TabType = ttTab) then begin
        inherited ActivePageIndex := Value;
        if not Pages[Value].TabVisible then
          SetParentUpdated(Pages[Value]); // Update because TCM_SETCURSEL is not received
    
        //Rafal
        if Assigned(OnPageChangeTab) then
          OnPageChangeTab(Self);
      end;
    end;
    
    destructor TsTabSheet.Destroy;
    var
      ParentTab: TWinControl;
    begin
      if AnimTimer <> nil then
        FreeAndNil(AnimTimer);
    
      FreeAndNil(FCommonData);
    
      //Remember parent
      ParentTab := Parent;
      inherited;
    
      //Rafal
      if (ParentTab is TsPageControl) and (Assigned(TsPageControl(ParentTab).OnPageChangeTab))
       then  TsPageControl(ParentTab).OnPageChangeTab(TsPageControl(ParentTab));
    
    end;  
    #68583
    HeDiBo
    Participant

    Can you explain which problem this change solves that is not handled by the OnChanging and OnChange events?

    #68584
    Rafał Drzewiecki
    Participant

    Hi, OnChanging and OnChange not handled:

    PageControl.ActivPageIndex := 2;
    PageControl.ActivPageIndex := 1;

    and

    PageControl.ActivPageIndex = 3;
    PageControl.Pages[2].Free;

    #68585
    HeDiBo
    Participant

    Very simple to build this yourself:

    procedure SetActiveTab(PC: TsPageControl; PageNr: Integer);
    var
       Accept: Boolean;
    begin
       PC.OnChanging(PC, Accept);
       if not Accept then Exit;
       PC.ActivePageIndex := PageNr;
       PC.OnChange(PC);
    end;
    
    #68586
    Rafał Drzewiecki
    Participant

    Yes ofcurse, This procedure is simple to write but you have to remember about it. This is only for changing tabs programmatically. It is necessary to write one more for TabSheet.Free;

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