>>From time to time I'm asked to enhance PageFrames by adding one or more new pages. Recently I added a seventh page to a pageframe and set its .PageOrder to 2 to make it the second page, rather than the last. All well and good.
>>
>>However, there is code in the parent form that depends on hard-coded .ActivePage values e.g.
>>
>>IF MyPageFrame.ActivePage = 3
>>...
>>
>>Most of these are now broken, because what used to be the 2nd page is now the 3rd, third is the 4th etc.
>>
>>Has anyone come up with a generic handler for this? My first thought is that the name of the page isn't likely to change, regardless of its .PageOrder so I could look at implementing something like
>>
>>IF MyPageFrame.ActivePageName( MyPageFrame.ActivePage ) = "SomePageName"
>>...
>>
>
>I faced a similar problem some time ago what I did was to add an array property (I did it on the form for I was planning to put it in the class later, which then I forgot until now that you mentioned..), I called PageToPageOrder, then in the init you can put code like this:
>
>
>local lnPage, loPage
>
>lnPage = 0
>DIMENSION this.PageToPageOrder(this.PageCount, 2)
>
>FOR EACH loPage IN this.Pages FOXOBJECT
> lnPage = lnPage + 1
> this.PageToPageOrder[loPage.PageOrder, 1] = lnPage
> this.PageToPageOrder[lnPage, 2] = loPage.PageOrder
>ENDFOR
>
>
>So now somewhere else where I needed I can do, for example:
>
>
>lnActivePage = thisform.myPageFrame.PageToPageOrder[thisform.myPageFrame.ActivePage, 1]
>loActivePage = evaluate('thisform.myPageFrame.page'+transform(lnActivePage))
>
>
>In your example you would change
>
>
>IF MyPageFrame.ActivePage = 3
>...
>
>
>to
>
>IF MyPageFrame.PageToPageOrder[MyPageFrame.ActivePage, 1] = 3
>...
>
Thanks, Hugo. What I'm trying to do is get rid of hard-coded page number or page order references and use something more generic like the Page.Name. So code that needs to run when a certain Page.Name is active can do so regardless of its design-time or run-time page order, and not be affected by other pages being inserted or removed.
I was doing a little testing and came up with this:
LPARAMETERS ;
toPageFrame
LOCAL ;
lcRetVal ;
, lnIx
WITH m.toPageFrame
FOR m.lnIx = 1 TO .PageCount STEP 1
IF .Pages( m.lnIx ).PageOrder = .ActivePage
m.lcRetVal = .Pages( m.lnIx ).Name
ENDIF
ENDFOR
ENDWITH
RETURN m.lcRetVal
So, if I add this method to a form MyForm that includes a PageFrame MyPgF:
IF MyForm.MyPgF.ActivePage = 3
IF MyForm.ActivePageName( MyForm.MyPgF ) = "Page3"
Regards. Al
"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov
Neither a despot, nor a doormat, be
Every app wants to be a database app when it grows up