------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - ACCESS AND ASSIGN METHODS
                                 January 2024
                 ------------------------------------------------------------
                                    CCB



1. BUG:

     In vfp9, we can use the Access and Assign methods to execute code when querying or changing property values,
     but when SET("STATUS BAR")="OFF" and SET("TALK")="ON", sometimes VFP will crash.

     1, There is a program for test:

     *PROC testaccessandassign

     SET STEP OFF
     SET ECHO OFF
     SET DEBUG OFF
     SET ESCAPE OFF
     SET TALK OFF
     SET SAFETY OFF

     _SCREEN.VISIBLE=.T.
     _SCREEN.WINDOWSTATE=2

     CLOSE DATABASES ALL
     CLOSE TABLES ALL

     SET STATUS BAR OFF
     SET TALK ON
     DO FORM testaccessandassign.scx

     CLOSE DATABASES ALL
     CLOSE TABLES ALL

     RETURN

     * END OF PROC TESTACCESSANDASSIGN.


     2, In the file testaccessandassign.scx:

     PROCEDURE olabel_access
     *To do: Modify this routine for the Access method
     IF TYPE("THIS.olabel")#"O"
        SET STATUS BAR OFF
        SET TALK ON
        WAIT WIND 'SET("STATUS BAR") = '+SET("STATUS BAR")
        WAIT WIND 'SET("TALK") = '+SET("TALK")
        THIS.olabel=THISFORM.label1
        WAIT WIND 'SET("STATUS BAR") = '+SET("STATUS BAR")
        WAIT WIND 'SET("TALK") = '+SET("TALK")
     ENDI
     RETURN THIS.olabel

     If we set the olabel property to a Logical data (or a Numeric data) in the Form Designer:
     olabel = .F.
     there is no problem.

     But if we set the olabel property to a Character data in the Form Designer:
     olabel = "aaa"
     after vfp run the code:
     THIS.olabel=THISFORM.label1
     VFP will crash.


     3, In the file Samples\chartssample_builder.scx of the FoxCharts v1.20:

     PROCEDURE ofoxcharts_access
     * Make sure we have a FoxCharts object
     IF VARTYPE(This.oFoxcharts) <> "O"
        This.oFoxcharts = EVALUATE(This.oFoxCharts)
     ENDIF
     RETURN This.oFoxcharts

     If we set the ofoxcharts property to a Character data in the Form Designer:
     ofoxcharts = "Thisform.FoxCharts1"
     after vfp run the code:
     This.oFoxcharts = EVALUATE(This.oFoxCharts)
     VFP will crash.

     There is no the PROCEDURE ofoxcharts_access in the FoxCharts v1.37b,
     so there is no the problem in the FoxCharts v1.37b.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun53cefe :: ; proc near
             cmp  byte ptr [esi] , 076h                                      ;0x0053cefe :        803e76
             je Label58d91f                                                  ;0x0053cf01 :        0f84180a0500

     Label53cf07 ::
             mov  ecx , dword ptr [ esi + 32 ]                               ;0x0053cf07 :        8b4e20
             test ecx , ecx                                                  ;0x0053cf0a :        85c9
             mov  byte ptr [esi] , 049h                                      ;0x0053cf0c :        c60649
             jne Label529447                                                 ;0x0053cf0f :        0f8532c5feff

     Label53cf15 ::
             mov  ecx , dword ptr [ esi + 36 ]                               ;0x0053cf15 :        8b4e24
             test ecx , ecx                                                  ;0x0053cf18 :        85c9
             jne Label5028ea                                                 ;0x0053cf1a :        0f85ca59fcff

     Label53cf20 ::
             mov  eax , dword ptr [ esi + 40 ]                               ;0x0053cf20 :        8b4628
             test eax , eax                                                  ;0x0053cf23 :        85c0
             jne Label58d92e                                                 ;0x0053cf25 :        0f85030a0500
             ret                                                             ;0x0053cf2b :        c3

     Label529447 ::


     ;
     ;                 -------------------------------------------------
     ;                      VFP 9.0 FIX - ACCESS AND ASSIGN METHODS
     ;                                 December 2014
     ;                 -------------------------------------------------
     ;                                     CCB
     ;
     ; Use the Access and Assign methods when SET("STATUS BAR")="OFF" and SET("TALK")="ON", sometimes VFP will crash.
     ;
     ; 2014/12/7, by ccb
     ;

             mov  ecx , dword ptr [ esi + 32 ]
             test ecx,ecx
             je Label52944c
             mov eax,dword ptr [ecx]
             test eax,eax
             je Label52944c
             push ecx
             push eax
             sub eax,08h
             push 08h
             push eax
             call vfpa_isbadreadptr
             test eax,eax
             pop eax
             pop ecx
             jne Label52944c
             push ecx
             push eax
             sub eax,08h
             push dword ptr [eax+04h]
             push eax
             call vfpa_isbadreadptr
             test eax,eax
             pop eax
             pop ecx
             jne Label52944c


             call Fun42c1e2                                                  ;0x00529447 :        e8962df0ff

     Label52944c ::
             mov  dword ptr [ esi + 32 ] , 00h                               ;0x0052944c :        c7462000000000
             jmp Label53cf15                                                 ;0x00529453 :        e9bd3a0100


4. APPLIES TO:

     VFP 6.0.8167.0
     VFP 6.0.8961.0 (SP5)

     VFP 7.0.0.9262
     VFP 7.0.0.9465 (SP1)

     VFP 8.0.0.2521
     VFP 8.0.0.3117 (SP1)

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix225.asp

     2, foxite.com:
     http://www.foxite.com/archives/vfp-c-compiler-and-app-0000362799.htm

     3, codeplex.com:
     http://vfpx.codeplex.com/wikipage?title=FoxCharts#


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.