在页面控件中从一个页面移动到另一个页面时如何检查上一个选项卡?

发布于 2024-08-02 12:59:49 字数 240 浏览 8 评论 0原文

我使用 TPageControl 隐藏 TTabsheets 的选项卡,以便使它们包含的框架看起来像是堆叠的,并通过在过程中的不同步骤显示不同的框架来构建某种向导。

问题是,在调用“PageControl1.ActivePageIndex := x;”之后要显示下一帧,一旦进入新帧,我需要知道我是如何到达这里的,即之前显示的是哪一帧。

如果其他人在页面控件中使用框架来构建向导,您如何跟踪上一个/下一个框架?

谢谢。

I'm using a TPageControl with the TTabsheets' tabs hidden so as to have the frames they contain appear to be stacked, and build some kind of wizard by displaying a different frame at different steps in the process.

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

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

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

最冷一天 2024-08-09 12:59:49

TPageControl 有一个名为 OnChanging 的事件,该事件在更改之前调用,并允许您通过将参数设置为 false 来取消更改。

您还可以使用此事件来记录更改之前哪个页面处于活动状态。

不过,我鼓励您制作一些与 gui 组件不那么紧密耦合的东西。尝试让某种类负责保存框架并检查是否允许从一个框架更改为另一个框架等等。这将使您更容易切换用于可视化向导的 GUI 控件类型。如果验证规则得到执行等等,这肯定会使测试向导是否提供了您想要的逐步进展变得更加容易。

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

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

I would encourage you to make something not as strongly coupled to a gui-component, though. Try to make some kind of class responsible for holding frames and checking if changing from one to another should be allowed and so on. This would make it easier to switch what type of gui control you would use to visualize the wizard. And it would for sure make it much more easier to test to see if your wizard gives the step-by-step progression that you want, if validation rules is enforced and so on.

烟燃烟灭 2024-08-09 12:59:49

delphi.about.com 上有一篇文章如何创建向导类似的用户界面。您可以使用 TPageControl.SelectNextPage 方法在一组页面中向前和向后移动。

On delphi.about.com is an article how to create a wizard-like user interface. You can use the TPageControl.SelectNextPage method to move forward and backward through a set of pages.

沒落の蓅哖 2024-08-09 12:59:49

与 Nat 的答案相反,如果您使用正确的方法来更改页面,tpagecontrol.onchanging 事件将正常工作:

创建一个 VCL 表单应用程序,然后放在 TPageControl 上,将 Align 属性设置为 alTop 并在下面留出一些空间。右键单击 PageControl 并添加一些页面,为每个页面设置 TabVisible:=false。现在在下面添加几个按钮。将 PageControl 的 onchanging 事件和按钮的 onclick 事件附加到下面的相应代码:

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;

这按预期工作(BDS2006、RAD2009)。

Contrary to Nat's answer, the tpagecontrol.onchanging event will work just fine if you use the right methods to change pages:

Create a VCL forms application, and drop on a TPageControl, set Align property to alTop and leave some room below. Right-click on the PageControl and add some pages, setting TabVisible:=false for each. Now add a couple of buttons below. Attach the PageControl's onchanging event, and the buttons' onclick events, to the respective 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).

z祗昰~ 2024-08-09 12:59:49

您可能还想查看属于 JEDI VCL 库一部分的向导组件。

You might also want to look at the Wizard component that's part of the JEDI VCL library.

孤独陪着我 2024-08-09 12:59:49

我编写了一个向导框架,它几乎可以完成您想要做的事情。其中大部分内容都记录在我的博客上。我使用的解决方案是将下一个/上一个页面的请求推送到框架本身(使用接口),并让框架决定下一帧应该是什么。

如果您想合并这两个想法(保持 tPageControl 不变),您可以将请求路由到 tPageControl.ActivePage,并且为了实现 NavigateToPage 可以查找您指定的页面,而不是尝试查找特定的页面班级。

我的向导框架的设计是为了处理一些复杂的向导,其中包含基于沿途做出的决策的多个路径。我将前面的帧存储在列表中,每个帧的“状态”存储在一个全局可访问的类中,一旦向导完成/取消,该类就会被清除。

I have written a wizard framework which does almost what your trying to do. Most of it is documented on my blog. The solution I used was to push the request for a next/prev page to the frame itself (using interfaces), and let the frame decide what the next frame should be.

If you wanted to merge the two ideas (keeping your tPageControl as is), you can just route the request to tPageControl.ActivePage, and for the implementation of NavigateToPage could do a lookup to the pages you have named rather than attempt to find a specific class.

The design of my wizard framework was to handle a few complex wizards which contained multiple paths based on decisions made along the way. I stored the previous frames in a list, and each frame's "state" was stored in a globally accessible class which was cleared once the wizard finished/canceled.

故事与诗 2024-08-09 12:59:49

您必须手动跟踪上一页索引。例如,在“下一个”和“上一个”按钮的 OnClick 事件处理程序中,您可以执行如下操作:

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

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

SwitchPage() 看起来像这样:

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;

或类似的操作。 :)

编辑: Argalatyr 是正确的,而我是不正确的,如果您想按顺序浏览向导,我将假设这里就是这种情况。

OnChanging 处理程序确实会触发,并且您来自的页面(仍然)是活动页面。

当您直接设置页面索引时(如我的示例所示),OnChanging 事件不会触发,因此您必须跟踪旧的页面索引。这来自于带有可选页面(非连续)的向导编码。

我应该在发帖之前仔细检查一下。对错误答案表示歉意。

氮@

You have to keep track of your previous page index manually. For example, in your Next and Previous button's OnClick event handlers, you could do something like this:

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

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

SwitchPage() would 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 to that effect. :)

Edit: Argalatyr is correct, and I am incorrect, in the case where you want to move through the wizard in sequential order, which I will assume is the case here.

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

The OnChanging event doesn't fire when you set the page index directly, as in my example, so you have to keep track of the old page index. This comes from coding up wizards with optional pages (not sequential).

I should have checked a little better before I posted. Appologies for the incorrect answer.

N@

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文