-------------------------------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - CLEAR THE COMPILED PROGRAM BUFFER AFTER CHANGE THE DEFAULT DIRECTORY
                                 January 2024
                 -------------------------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), it will not clear the compiled program buffer after change the default directory
     with the CHDIR (or CD) command or the SET DEFAULT command.

     In Visual FoxPro Advanced, if we set SYS(9118,1) in Visual FoxPro Advanced,
     it will clear the compiled program buffer after change the default directory
     with the CHDIR (or CD) command or the SET DEFAULT command when Visual FoxPro Advanced is not running in a VFP API Library routine.

     Usually, the following commands will clear the compiled program buffer automatically:
     Activate another application, when Visual FoxPro is running in interactive mode (in the command window)
     CLEAR PROGRAM command
     DOEVENTS command
     MODIFY COMMAND command and MODIFY FILE command, specify the name of the text editor (TEDIT = [/N] editor) in the configuration file
     RUN or ! command, when Visual FoxPro is not running in a VFP API Library routine
     SET DEVELOPMENT ON command
     CHDIR (or CD) command and SET DEFAULT command, when Visual FoxPro Advanced is not running in a VFP API Library routine

     There is a test program:

     *PROC testcdcommand

     CD test1
     DO testcdcommand2 && calls test1\testcdcommand2.prg
     CD ..

     CD test2
     DO testcdcommand2 && calls test1\testcdcommand2.prg in vfp9! calls test2\testcdcommand2.prg in Visual FoxPro Advanced, ok.
     CD ..

     CD test2
     CLEAR PROGRAM
     DO testcdcommand2 && calls test2\testcdcommand2.prg, ok.
     CD ..

     RETURN

     * END OF PROC TESTCDCOMMAND.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label45e0a0 ::
             push ebp                                                        ;0x0045e0a0 :        55
             mov ebp , esp                                                   ;0x0045e0a1 :        8bec
             sub esp , 064h                                                  ;0x0045e0a3 :        83ec64
             mov eax ,  dword ptr [ Data9393ac ]                             ;0x0045e0a6 :        a1ac939300
             cmp  byte ptr [eax] , 0FEh                                      ;0x0045e0ab :        8038fe
             push ebx                                                        ;0x0045e0ae :        53
             push esi                                                        ;0x0045e0af :        56
             push edi                                                        ;0x0045e0b0 :        57
             mov  dword ptr [ ebp - 4 ] , 00h                                ;0x0045e0b1 :        c745fc00000000
             je Label598807                                                  ;0x0045e0b8 :        0f8449a71300
             pushd 00h                                                       ;0x0045e0be :        6a00
             call Fun4b57e5                                                  ;0x0045e0c0 :        e820770500


     ;
     ;                 --------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - CLEAR THE COMPILED PROGRAM BUFFER AFTER CHANGE THE DEFAULT DIRECTORY
     ;                                 January 2023
     ;                 --------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; In vfp9 (and vfp6, vfp7, vfp8), it will not clear the compiled program buffer after change the default directory
     ; with the CHDIR (or CD) command or the SET DEFAULT command.
     ; In Visual FoxPro Advanced, it will clear the compiled program buffer after change the default directory
     ; with the CHDIR (or CD) command or the SET DEFAULT command when Visual FoxPro Advanced is not running in a VFP API Library routine.
     ;
     ; 2023/1/23, by ccb
     ;

             cmp dword ptr vfpa_sys9118_data,00h
             je Label45e0c5
             cmp dword ptr vfpa_runafterbuild_isrunafterbuild,01h
             jne Label45e0c2
             mov dword ptr vfpa_runafterbuild_isrunafterbuild,00h
             jmp Label45e0c5
     Label45e0c2 ::
             cmp dword ptr vfpa_optionsdialog_isoptionsdialog,01h
             jne Label45e0c3
             mov dword ptr vfpa_optionsdialog_isoptionsdialog,00h
             jmp Label45e0c5
     Label45e0c3 ::
             mov eax ,  dword ptr [ Data941124 ]
             test eax , eax
             je Label45e0c4
             cmp  dword ptr [ eax + 16 ] , 00h
             je Label45e0c4
             jmp Label45e0c5
     Label45e0c4 ::
             cmp  word ptr [ Data937100 ] , 00h
             jne Label4b6a0b
             call Fun4cf664
             jmp Label4b6a0b


     Label45e0c5 ::
             pop edi                                                         ;0x0045e0c5 :        5f
             pop esi                                                         ;0x0045e0c6 :        5e
             pop ebx                                                         ;0x0045e0c7 :        5b
             mov esp , ebp                                                   ;0x0045e0c8 :        8be5
             pop ebp                                                         ;0x0045e0ca :        5d
             ret                                                             ;0x0045e0cb :        c3


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_vfp9fix239.asp


6. OTHER:

     For reference only, there is no guarantees.

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