How to check the previous tab when navigating from page to page in pagecontrol?

I am using TPageControl with the TTabsheets hidden to have frames associated with them and create some kind of wizard displaying a different frame at different stages of the process.

The problem is that after calling "PageControl1.ActivePageIndex: = x;" to display the next frame, once in a new frame, I need to know how I got here, that is, which frame was previously displayed.

If anyone else has used frames in pagecontrol to create a wizard, how do you keep track of the previous / next frames?

Thank.

+2


source to share


6 answers


TPageControl has an OnChanging event that is called before the change and allows you to cancel the change by setting the parameter to false.

You can also use this event to record which page was active before the change.



I would advise you to do something less gui-related. Try to make some class responsible for holding frames and check if it is allowed to jump from one to the other, and so on. This will make it easier to switch the type of gui control you will use to render the wizard. And it will surely make the validation a lot easier if your wizard gives you a step-by-step progression, if you want validation rules to be followed, etc.

+5


source


Delphi.about.com has an article on how to create a master user interface. You can use the TPageControl.SelectNextPage method to move forward and backward through a set of pages.



+1


source


Unlike Nat's answer, the event tpagecontrol.onchanging

will work just fine if you use the correct methods to change pages:

Build a VCL forms app and leave on TPageControl

, set the Align property to alTop and leave some space below. Right click on PageControl and add multiple pages, setting TabVisible:=false

for each. Now add a couple of buttons below. Attach the PageControl event onchanging

and the << 24> buttons to the appropriate code below:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if PageControl1.ActivePageIndex < PageControl1.PageCount - 1 then
    PageControl1.SelectNextPage(true, false);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if PageControl1.ActivePageIndex > 0 then
    PageControl1.SelectNextPage(false, false);
end;

procedure TForm1.PageControl1Changing(Sender: TObject;
  var AllowChange: Boolean);
begin
  showmessage(format('now leaving page number %d', [PageControl1.ActivePageIndex]));
end;

      

This works as expected (BDS2006, RAD2009).

+1


source


You can also take a look at the Wizard component, which is part of the JEDI VCL library.

0


source


I wrote a wizard framework that does almost what you are trying to do. Most of them are documented on my blog . The solution I used was to route the next / previous page request to the frame itself (using interfaces) and let the frame decide what the next frame should be.

If you want to combine the two ideas (keeping your tPageControl as it is), you can simply redirect the request to tPageControl.ActivePage, and for the NavigateToPage implementation, you can search through the pages you specify, rather than trying to find a specific class.

The design of my layout infrastructure was to handle multiple complex wizards that contained multiple paths based on the decisions made along the way. I kept the previous frames in the list, and each frame state was saved in a globally accessible class that was cleared after the wizard finished or canceled.

0


source


You have to track your previous page index manually. For example, in the following and previous OnClick event handlers, you can do something like this:

procedure TWizardForm.NextClick(ASender: TObject);
begin
  SwitchPage(True);
end;

procedure TWizardForm.PreviousClick(ASender: TObject);
begin
  SwitchPage(False);
end;

      

SwitchPage () will look something like this:

procedure TWizardForm.SwitchPage(AForward: boolean);
var
  LGotoPage: integer;
begin
  LGotoPage := PageControl.ActivePageIndex;

  if AForward and (PageControl.ActivePageIndex < PageControl.PageCount) then
    inc(LGotoPage)
  else if PageControl.PageIndex > 0 then
    dec(LGotoPage);

  if (LGotoPage <> PageControl.ActivePageIndex) 
    and AllowSwitchFrom(ActivePageIndex) then
  begin
    FPreviousPage := PageControl.ActivePageIndex;
    PageControl.ActivePageIndex :=  LGotoPage;
  end;

end;

      

Or something like that.:)

Edit: Argalatir is correct and I am wrong if you want to navigate through the master in sequential order, which I will count here.

The OnChanging handler does fire, and the page you are leaving is (still) the active page.

The OnChanging event does not fire when you set the page index directly like in my example, so you need to keep track of the old page index. This comes from coding wizards with extra pages (not sequential).

I should have checked a little better before I posted. Wrong answer statements.

N @

0


source







All Articles