Should I use delphi tframes for multi-pages forms?

前端 未结 4 1360
轮回少年
轮回少年 2021-02-04 15:04

I have some forms in my application which have different \"states\" depending on what the user is doing; for exemple when listing through his files the form displays some data a

4条回答
  •  一向
    一向 (楼主)
    2021-02-04 15:25

    I have a word for you : TFrameStack. Simply what the name suggests.

    It has a few methods: PushFrame(AFrame), PopFrame, PopToTop(AFrame), PopToTop(Index), and a few Properties: StackTop; Frames[Index: Integer]; Count;

    • Should be self explanatory.

    The Frame at StackTop is the visible one. When doing ops like Back/Previous you don't need to know what frame was before the current one :) When creating the Frame you can create and push it in one go FrameStack.Push(TAFrame.Create) etc, which creates it calls the BeforeShow proc and makes it visible, returning its index in the stack :)

    But it does rely heavily on Inheriting your frames from a common ancestor. These frames all (in my Case) have procedures: BeforeShow; BeforeFree; BeforeHide; BeforeVisible. These are called by the FrameStack Object during push, pop and top;

    From your main form you just need to access FrameStack.Stacktop.whatever. I made my Stack a global :) so it's really easy to access from additional dialogs/windows etc.

    Also don't forget to create a Free method override to free all the frames ( if the owner is nil) in the stack when the app is shut down - another advantage you don't need to track them explicitly:)

    It took only a small amount of work to create the TFrameStack List object. And in my app work like a dream.

    Timbo

提交回复
热议问题