Recent

Author Topic: Error Changing PageControl ActiveTab via Code  (Read 2425 times)

PhilC

  • New Member
  • *
  • Posts: 10
Error Changing PageControl ActiveTab via Code
« on: March 06, 2020, 06:14:45 pm »
Not sure what is going wrong here.   I have a PageControl on a form with two tabs.

On Tab One I have a TStringGrid on Tab Two I have a button.   The StringGrid has OnDoubleClick set to change the Active Tab to Tab2 - see code below...

The Tab changes, but when I click on the Button on Tab Two, I get an exception "EInvalidOperation with the message: Cannot focus a disabled or invisible window"

This is on Mac OS: 10.15.3 (19D76) - Lazarus Version #: 2.0.6 -Date: 2019-11-05 - FPC Version: 3.0.4

Anyone an idea how I fix this?

Thanks

Code: Pascal  [Select][+][-]
  1. type
  2.  
  3.   { TForm1 }
  4.  
  5.   TForm1 = class(TForm)
  6.     Button2: TButton; // Button on Tabsheet2
  7.     PageControl1: TPageControl;
  8.     StringGrid1: TStringGrid;  // On TabSheet1
  9.     TabSheet1: TTabSheet;
  10.     TabSheet2: TTabSheet;
  11.     procedure StringGrid1DblClick(Sender: TObject);
  12.   private
  13.  
  14.   public
  15.  
  16.   end;
  17.  
  18. var
  19.   Form1: TForm1;
  20.  
  21. implementation
  22.  
  23. {$R *.lfm}
  24.  
  25. { TForm1 }
  26.  
  27.  
  28. procedure TForm1.StringGrid1DblClick(Sender: TObject);
  29. begin
  30.   PageControl1.ActivePage := TabSheet2;
  31. end;
  32.  
  33. end.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Error Changing PageControl ActiveTab via Code
« Reply #1 on: March 06, 2020, 11:24:51 pm »
must be a widget problem, it works fine here with win32 widget.

Try using the pageIndex instead and see what happens..

 also try using Applicaton.ProcessMessages before leaving the onclick of changing the page.
The only true wisdom is knowing you know nothing

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Error Changing PageControl ActiveTab via Code
« Reply #2 on: March 07, 2020, 12:56:11 am »
Works for the 32 bit Carbon widget set; confirmed fails for the 64 bit Cocoa widget set.

No need for a button on tabsheet 2 - simply clicking on tabsheet 2 causes the error.

Note that if you click on the tab for tabsheet2 everything works as expected. I use tabs extensively and have always just clicked on the tab to change tab sheets.

I'd continue this thread in the Cocoa widget set forum.

[Update:  Cool - the thread was moved here :)

Attached a demo project showing the problem]

« Last Edit: March 07, 2020, 01:35:36 am by trev »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Error Changing PageControl ActiveTab via Code
« Reply #3 on: March 07, 2020, 06:36:28 am »
try to call ReleaseCapture before changing activePage.
see if the workaround helps

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Error Changing PageControl ActiveTab via Code
« Reply #4 on: March 07, 2020, 08:31:26 am »
Yes! The workaround works.

PhilC

  • New Member
  • *
  • Posts: 10
Re: Error Changing PageControl ActiveTab via Code
« Reply #5 on: March 07, 2020, 10:50:21 am »
Sorry newbie error here I think; but how do I call ReleaseCapture?

I have included it before charging the ActivePage, but it errors Identifer Not Found - code below...

This is on Mac OS: 10.15.3 (19D76) - Lazarus Version #: 2.0.6 -Date: 2019-11-05 - FPC Version: 3.0.4

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1DblClick(Sender: TObject);
  2. var
  3.   p: TPoint;
  4.   row: integer;
  5.   col: integer;
  6.   account: String;
  7. begin
  8.   p := StringGrid1.ScreenToClient(Mouse.CursorPos);
  9.   StringGrid1.MouseToCell(p.X, p.y, col, Row);
  10.   if (Row >0) then
  11.   begin
  12.     account := StringGrid1.Cells[0,row];
  13.     if account <> 'Totals' then
  14.     begin
  15.          TabSheet2.Caption := StringGrid1.Cells[0,row];
  16.          ReleaseCapture;
  17.          PageControl1.ActivePage := TabSheet2 ;
  18.  
  19.     end;
  20.   end;
  21. end;

eljo

  • Sr. Member
  • ****
  • Posts: 468
Re: Error Changing PageControl ActiveTab via Code
« Reply #6 on: March 07, 2020, 12:47:39 pm »
Sorry newbie error here I think; but how do I call ReleaseCapture?

I have included it before charging the ActivePage, but it errors Identifer Not Found - code below...
Code: Pascal  [Select][+][-]
  1. uses lclintf....
  2. .
  3. .
  4. .
  5. begin
  6. ...
  7. .....
  8.  lclintf.ReleaseCapture
  9. end;
  10.  

PhilC

  • New Member
  • *
  • Posts: 10
Re: Error Changing PageControl ActiveTab via Code
« Reply #7 on: March 07, 2020, 12:49:54 pm »
Many thanks  :D

 

TinyPortal © 2005-2018