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!

Is there a better way to get Active pageframe's caption?

Status
Not open for further replies.

EzLogic

Programmer
Aug 21, 2001
1,230
US
I have a pageframe with over 30 pages on it, the tabs are hidden, and the user navigates to the pages using a Grid and based on the Grid's click event/afterrowcolumn change, i active the appropriate page.

In another methd, i want to get the caption of the current active pageframe. (or reference to it)

this is how i came up with it.. i am wondering if there is another easiser way.

Method to get which page i am on... (mind you, the page order is not the same as the .Activepage result)

Code:
Local lnPage, lnIndex, loPage, loRetPage
lnPage = thisform.pgDocs.ActivePage 
loRetPage = ""
FOR lnIndex = 1 TO thisform.pgDocs.PageCount 
	loPage  = thisform.pgDocs.Pages(lnIndex)
	lnOrder = loPage.PageOrder 
	IF lnPage = lnOrder
	   loRetPage = loPage
           Exit
	ENDIF 
ENDFOR 
Return loRetPage

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Follow up:

I do this when i call the method to get the caption or anything.

loPage = thisform.GetPageName()
if type("loPage") <> "O"
return
endif
lcName = loPage.Caption
bla bla
bla bla



Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Hi Ali,

You say you want the caption of the active pageframe. I assume you meant the active page?

Given that you can't be sure that the page order is consecutive, the way you are doing it is the only possibility (as far as I can see). The only small improvement I can suggest is to use FOR EACH / ENDFOR rather than FOR lnIndex = 1 TO thisform.pgDocs.PageCount / ENDFOR. But the basic idea is the same.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks Mike, I figured there isn't another easy way.

You're right, i did mean active page. :)

i will switch it to for each / endfor ..

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
If the page is active and also a control on it has focus, how about thisform.activecontrol.parent.caption? The only problem there is, if the page control having focus isn't a direct child object of the page, eg if it's a textbox in a grid on a page.

There is no such thing as thispage, but even in case your object hierachy is not flat, you could always start at a control and step up the parent hierarchy, until you reach a page object.

You could also create a page class having this in activate event: Addproperty(Thisform,"ActivePage",This)
Then, if you never suppress that base class code, you could always look into Thisform.activepage.

Bye, Olaf.
 
You could also create a page class having this in activate event: Addproperty(Thisform,"ActivePage",This)

I like this. The page announces itself and nothing outside of it needs to be concerned with its inner workings. Should the inner behavior of the pageframe or its requirements change, IT changes the object stored in the form reference.

It's a little meta, but it's very much the proper assignment of responsibilities.

Just make sure to null that property on exit to avoid the dreaded dangling reference!
 
NULLing the activepage property is a good idea, but there's another flaw with it: If you have two pageframes side to side, you have two active pages of two pageframes. This is something I never did, but already saw. It can make sense. So perhaps this should just be modified to ADDPROPERTY(This.Parent,"ActivePage",This), so it's a property of the pageframe, not of the form.

More important than initing with NULL and NULLing it, when a page is removed, is the usage: Like with form.activecontrol you should always check, whether it's a valid object reference or NULL, before using it.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top