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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigation toolbar to work across private datasessions wanted 2

Status
Not open for further replies.

RobWinder

Programmer
Nov 2, 2003
3
GB
Hello people,

I want to put a single fairly standard navigation toolbar on screen (or docked) to use with any table that might be in use at any time throughout the application. I defined a nav toolbar as a class, & put it on a formset along with other forms, and at first that seemed OK, the record pointer moves in the currently selected table, and any pointers to child records change correctly. I want to use multiple instances of the formset with private datasessions, but I don’t want lots of toolbars.
Using VFP8 and Wxp or W2000.
Q1: How do I put the toolbar on the screen, and not linked to a form or formset?
Q2: How do I pass the info it will need to operate in the right table depending on which formset I’m currently working in?

Sorry if this isn’t too clear, I have a problem with leaving messages on answerphones as well..thanks in advance
Robwinder
 
Robwinder,

Basically, you need a way of knowing which form is active at the time that the toolbar is being used, and then switching to that form's datasession.

So, you would need something like this (in the Click event of a toolbar button, for example):

SET DATASESSION TO _SCREEN.ActiveForm.DataSessionID

It's also a good idea to check that there is indeed an active form before you execute the above; if there isn't, you will get an error. Use _SCREEN.Formcount to check if there is an active form.

Finally, I know this doesn't answer your question, but in general I would avoid using formsets. They are only supported for backward compatibility, and they introduce unnecessary complications.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Thanks Mike. DataSessionID: obvious when you think about it - or when someone else points it out!
 
SET DATASESSION TO _SCREEN.ActiveForm.DataSessionID

This should work for you, but just as a warning: the SET DATASESSION command can get kinda wacky: it changes the official datasession of the "current" object (supposed to be the object that contains the code with the SET DATASESSION command in it), so all future code in that object will use that datasession. That's okay for your toolbar that does only this, but can get hairy if the object does anything else.

The help says of this command: SET DATASESSION typically is used to debug forms. Care should be taken when issuing this command when a form is active, because tables in non-current datasessions are not accessible.

Another way to accomplish the same thing and be more flexible (that is, not force the currently selected alias to be the table that gets SKIP'ed) is to create methods on your base data form class: GoNext, GoPrev, GoFirst, GoLast, etc, and in your toolbar buttons, put code like this:

Code:
IF TYPE('_SCREEN.ActiveForm.name')='C'
  if PEMSTATUS(_SCREEN.ActiveForm,'GoNext',5)
    _SCREEN.ActiveForm.GoNext
  endif
ENDIF
*****
*or, use just one method:
IF TYPE('_SCREEN.ActiveForm.name')='C'
  if PEMSTATUS(_SCREEN.ActiveForm,'Navigate',5)
    _SCREEN.ActiveForm.Navigate('NEXT')
  endif
ENDIF

This way, the form can do whatever it needs to in order to goto the NEXT, PREV, FIRST, LAST, or even FIND (pop up a search window then do a SEEK). Any "verbs" that are unknown to a form could be ignored:
Code:
PROCEDURE MyDataForm.Navigate( tcVerb )
DO CASE
  CASE VARTYPE(tcVerb)<>'C'
    RETURN .F.
  CASE tcVerb='NEXT'
    SELECT MyAlias
    SKIP
    THISFORM.ReloadDataValues
  CASE tcVerb='FIND'
    SELECT MyAlias
    SET ORDER TO myOrd
    lcFind = INPUTBOX("Enter a name to find:")
    if not empty(lcFind)
      SEEK (lcFind)
      if not found()
        MessageBox("Not Found!")
      else
        THISFORM.ReloadDataValues
      endif
    endif
ENDCASE
ENDPROC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top