Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing Tabsheets to exit

Status
Not open for further replies.

TompaD

Technical User
Oct 2, 2003
6
SE
Is there a way to stop a pagecontrol to shift tabsheets if a
certain condition is fullfilled??


I have a tabsheet with some checkboxes and if any of them is not checked I don´t want the tabsheet to change if I click the other tabs.

Regards
TompaD

Yes I´m a newbie on Delphi (sort of)
 
Straight from the D5 helpfile on the OnChanging event of TPageControl:
<snip>
Write an OnChanging event handler to take specific action immediately before the selected tab changes. Set the AllowChange parameter to False to prevent the change.

Use an OnChanging event handler to prevent the user from leaving a tab setting until certain conditions have been met. An OnChanging event handler can also be used to save information about the current state of the tab control before it is changed by a new tab selection.
</snip>

HTH
TonHu

P.s.: Don't hesitate to use Ctrl-F1 for context sensitive help ;-)
 
Yes, simply set the ActivePage property of the PageControl to the TabSheet that you want to stay selected in the OnChange event handler of the PageControl.

So your OnChange event handler will look something like this (if you want to stay on TabSheet3):
Code:
procedure TForm1.PageControl1Change(Sender: TObject);
begin
  if AnyCheckBoxNotChecked then 
    PageControl1.ActivePage := TabSheet3;
end;

Andrew
 
Well, I'm talking about the OnChanging event s-) so no fuss with ActivePage, just a nice case statement with checks like:
Code:
procedure TForm1.TPageControl1Changing(Sender: TObject;
  var AllowChange: Boolean);
begin

case TPageControl1.ActivePageIndex of
...
3 : AllowChange := CheckAllChecksForTabsheet3();
...
end;  // Case

end;  // Procedure

If you need to use TabSheet3 like statements instead of having TabSheet3 on PageIndex 3, then you can't use case, but have to apply a series of if's like in
Code:
...
if TPageControl1.ActivePage = TabSheet3 then
   AllowChange := CheckAllChecksForTabsheet3()
else
if TPageControl1.ActivePage = TabSheet4 then
...

HTH
TonHu
 
To all answerers - THANKS!! :)

And yes TonHu, you are right! ;-)
But it´s seems that I always get lost in the helpfile,
maybe its because my cold.....

Thanks again all!

Regards
TompaD
Sweden
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top