Search code examples
visual-foxprofoxpro

In FoxPro, why is selected table changing within form if form called from a button in a grid?


I have a master form that calls a form called freight.
This freight form has all properties set to default except Caption, Name and window type which is 1-Modal. The only method with code is the init which has:

select FRT1

The only object on the form is a command button with this in the click method:

messagebox(alias())
thisform.release()

So I would expect when I press the command button, the messagebox would say [FRT1] but instead it gives another alias from the master form.

Before the form is called from the master form, the alias is also explicitly set to FRT1

select FRT1
do form freight

Because the Freight form is modal, I would expect nothing in the master form to affect the data areas while the Freight form is running.

Since there is practically nothing in the Freight form, the problem would seem to be in the master form.

This errant behavior seems to only occur if the freight form is called from a button within a grid. Any ideas on what is happening or how to prevent it?


Solution

  • Just a few thoughts.

    I would open your debugger and put a

    SET STEP ON
    

    immediately before doing the

    SELECT FRT1
    DO FORM FREIGHT
    

    Then, in the debugger, go to the "Watch" window and enter the value

    ALIAS()
    

    as the value to watch and to a click in the left-bar to show the red dot to STOP when it changes.

    Just a thought of expectation. Your "Freight" form has its "DataSession" property to "1-Default data session", and if so, it is looking at whatever alias is in the DEFAULT session and not a PRIVATE data session that your master form may have...

    I have seen this only EXTREMELY RARE cases ( 2 times ever in the 25+ yrs of working with FoxBase, FoxPro, VFP). In these cases, I had to EXPLICITLY do a select of the table TWICE in a row.

    SELECT FRT1
    SELECT FRT1
    

    or even putting a bogus statement in between such as

    SELECT FRT1
    tmpXXXXXX = alias()
    SELECT FRT1
    

    Check with breakpoint and see if that works.

    Only one other breakpoint I would TRY to do... put "PROGRAM()" in the watch window. Is it possibly calling some other derived class script you did not know about... or in the "DataEnvironment" of the form running code such as in the "BeforeOpenTables" event? Better to KNOW where its doing things than bypass