-------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - INITIALIZE THE REPORT SYSTEM VARIABLES
                                  March 2024
                 -------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (vfp9 IDE, vfp9 Runtime and vfp9 Multi-threaded Runtime),
     it will search the report application files (REPORTBUILDER.APP, REPORTPREVIEW.APP and REPORTOUTPUT.APP) in the Visual FoxPro start folder (HOME()),
     if the file is found, it will initialize the report system variables (_REPORTBUILDER, _REPORTPREVIEW and _REPORTOUTPUT) to the file,
     if the file is not found, it will initialize the report system variables (_REPORTBUILDER, _REPORTPREVIEW and _REPORTOUTPUT) to an empty string.
     
     In VFP Advanced IDE (it is the same as vfp9 IDE),
     it will search the report application files (REPORTBUILDER.APP, REPORTPREVIEW.APP and REPORTOUTPUT.APP) in the Visual FoxPro start folder (HOME()),
     if the file is found, it will initialize the report system variables (_REPORTBUILDER, _REPORTPREVIEW and _REPORTOUTPUT) to the file,
     if the file is not found, it will initialize the report system variables (_REPORTBUILDER, _REPORTPREVIEW and _REPORTOUTPUT) to an empty string.

     In VFP Advanced Runtime and VFP Advanced Multi-threaded Runtime,
     it will search the report application files (REPORTBUILDER.APP, REPORTPREVIEW.APP AND REPORTOUTPUT.APP) in the following folders:
     1, the application folder,
     2, the Windows System folder,
     3, the Visual FoxPro start folder (HOME()), for example, the "C:\Program Files\Common Files\Microsoft Shared\VFP" folder,
     if the file is found, it will initialize the report system variables (_REPORTBUILDER, _REPORTPREVIEW and _REPORTOUTPUT) to the file,
     if the file is not found, it will initialize the report system variables (_REPORTBUILDER, _REPORTPREVIEW and _REPORTOUTPUT) to an empty string.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     Func00a99a :: ; proc near
             push ebp                                                        ;0x0c00a99a :        55
             lea ebp ,  dword ptr [ esp + 0FFFFFE08h ]                       ;0x0c00a99b :        8dac2408feffff
             sub esp , 0288h                                                 ;0x0c00a9a2 :        81ec88020000
             mov eax ,  dword ptr [ Datac41a174 ]                            ;0x0c00a9a8 :        a174a1410c
             mov  dword ptr [ ebp + 01F4h ] , eax                            ;0x0c00a9bb :        8985f4010000
             push ebx                                                        ;0x0c00a9ad :        53
             push esi                                                        ;0x0c00a9ae :        56
             push edi                                                        ;0x0c00a9c9 :        57


     ;
     ;                 --------------------------------------------------------------
     ;                      VFP 9.0 FIX - INITIALIZE THE REPORT SYSTEM VARIABLES
     ;                                  March 2024
     ;                 --------------------------------------------------------------
     ;                                     CCB
     ;
     ; Initialize the report system variables.
     ;
     ; 2024/3/3, by ccb
     ;

             mov byte ptr [ ebp + 0E7h ] , 00h

     Labelc00a9ae ::
             cmp dword ptr [ ebp + 0200h ] , 26h
             je Labelc00a9ae_GENGRAPH
             cmp dword ptr [ ebp + 0200h ] , 27h
             je Labelc00a9ae_GENPD
             cmp dword ptr [ ebp + 0200h ] , 45h
             je Labelc00a9ae_GETEXPR
             cmp dword ptr [ ebp + 0200h ] , 46h
             je Labelc00a9ae_INCLUDE
             cmp dword ptr [ ebp + 0200h ] , 55h
             je Labelc00a9ae_REPORTBUILDER
             cmp dword ptr [ ebp + 0200h ] , 56h
             je Labelc00a9ae_REPORTPREVIEW
             cmp dword ptr [ ebp + 0200h ] , 57h
             je Labelc00a9ae_REPORTOUTPUT
             jmp Labelc00a9af

     Labelc00a9ae_GENGRAPH ::
             pushd offset Datac3fcea0
             pushd 026h
             pop eax
             call Func008aab
             jmp Labelc00a9af

     Labelc00a9ae_GENPD ::
             pushd offset Datac3fce98
             pushd 027h
             pop eax
             call Func008aab
             jmp Labelc00a9af

     Labelc00a9ae_GETEXPR ::
             pushd offset Datac40132c
             pushd 045h
             pop eax
             call Func008aab
             jmp Labelc00a9af

     Labelc00a9ae_INCLUDE ::
             pushd offset Datac401320
             pushd 046h
             pop eax
             call Func008aab
             jmp Labelc00a9af

     Labelc00a9ae_REPORTBUILDER ::
             pushd offset Datac3fce88
             pushd 055h
             pop eax
             call Func008aab
             jmp Labelc00a9af

     Labelc00a9ae_REPORTPREVIEW ::
             pushd offset Datac3fce78
             pushd 056h
             pop eax
             call Func008aab
             jmp Labelc00a9af

     Labelc00a9ae_REPORTOUTPUT ::
             pushd offset Datac3fce68
             pushd 057h
             pop eax
             call Func008aab
             jmp Labelc00a9af


     Labelc00a9af ::
             mov  esi , dword ptr [ ebp + 0200h ]                            ;0x0c00a9af :        8bb500020000
             lea esi ,  dword ptr [ esi + 2 * esi ]                          ;0x0c00a9b5 :        8d3476
             shl esi , 03h                                                   ;0x0c00a9b8 :        c1e603
             mov  eax , dword ptr [ esi + offset Datac41af98 ]                      ;0x0c00a9c1 :        8b8698af410c
             test eax , eax                                                  ;0x0c00a9c7 :        85c0
             je Labelc00ab19                                                 ;0x0c00a9ca :        0f8449010000
             cmp eax , 0105h                                                 ;0x0c00a9d0 :        3d05010000
             jnb Labelc00ab19                                                ;0x0c00a9d5 :        0f833e010000
             mov  eax , dword ptr [ esi + offset Datac41afa0 ]                      ;0x0c00a9db :        8b86a0af410c
             test eax , eax                                                  ;0x0c00a9e1 :        85c0
             je Labelc00ab19                                                 ;0x0c00a9e3 :        0f8430010000
             mov  ecx , dword ptr [eax]                                      ;0x0c00a9e9 :        8b08
             mov ebx , 0106h                                                 ;0x0c00a9eb :        bb06010000
             mov edx , ebx                                                   ;0x0c00a9f0 :        8bd3
             lea eax ,  dword ptr [ ebp + 0E8h ]                             ;0x0c00a9f2 :        8d85e8000000
             call Func02661c                                                 ;0x0c00a9f8 :        e81fbc0100
             lea eax ,  dword ptr [ ebp + 0E8h ]                             ;0x0c00a9fd :        8d85e8000000
             pushd 03Ah                                                      ;0x0c00aa03 :        6a3a
             push eax                                                        ;0x0c00aa05 :        50
             call  dword ptr [ Datac41a19c ]                                 ;0x0c00aa06 :        ff159ca1410c
             test eax , eax                                                  ;0x0c00aa0c :        85c0
             pop ecx                                                         ;0x0c00aa0e :        59
             pop ecx                                                         ;0x0c00aa0f :        59
             jne Labelc00ab31                                                ;0x0c00aa10 :        0f851b010000
             lea eax ,  dword ptr [ ebp + 0E8h ]                             ;0x0c00aa16 :        8d85e8000000
             pushd 05Ch                                                      ;0x0c00aa1c :        6a5c
             push eax                                                        ;0x0c00aa1e :        50
             call  dword ptr [ Datac41a19c ]                                 ;0x0c00aa1f :        ff159ca1410c
             test eax , eax                                                  ;0x0c00aa25 :        85c0
             pop ecx                                                         ;0x0c00aa27 :        59
             pop ecx                                                         ;0x0c00aa28 :        59
             jne Labelc00ab31                                                ;0x0c00aa29 :        0f8502010000


     ;
     ;                 --------------------------------------------------------------
     ;                      VFP 9.0 FIX - INITIALIZE THE REPORT SYSTEM VARIABLES
     ;                                  March 2024
     ;                 --------------------------------------------------------------
     ;                                     CCB
     ;
     ; Initialize the report system variables.
     ;
     ; 2024/3/3, by ccb
     ;

             cmp dword ptr [ ebp + 0200h ] , 26h
             je Labelc00aa2c
             cmp dword ptr [ ebp + 0200h ] , 27h
             je Labelc00aa2c
             cmp dword ptr [ ebp + 0200h ] , 45h
             je Labelc00aa2c
             cmp dword ptr [ ebp + 0200h ] , 46h
             je Labelc00aa2c
             cmp dword ptr [ ebp + 0200h ] , 55h
             je Labelc00aa2c
             cmp dword ptr [ ebp + 0200h ] , 56h
             je Labelc00aa2c
             cmp dword ptr [ ebp + 0200h ] , 57h
             je Labelc00aa2c
             jmp Labelc00aa2f

     Labelc00aa2c ::
             cmp byte ptr [ ebp + 0E7h ] , 00h
             je Labelc00aa2d
             cmp byte ptr [ ebp + 0E7h ] , 01h
             je Labelc00aa2e
             cmp byte ptr [ ebp + 0E7h ] , 02h
             je Labelc00aa2f
             jmp Labelc00aa2f

     Labelc00aa2d ::
             lea eax ,  dword ptr [ ebp + 0E8h ]
             push eax
             pushd 0104h
             call  GetCurrentDirectoryA
             lea eax ,  dword ptr [ ebp + 0E8h ]
             push eax
             call lstrlenA
             lea ecx ,  dword ptr [ ebp + 0E8h ]
             add eax , ecx
             cmp byte ptr [eax] , 05Ch
             je Labelc00aa54
             mov byte ptr [eax] , 05Ch
             mov byte ptr [eax+1] , 00h
             jmp Labelc00aa54

     Labelc00aa2e ::
             pushd 0104h
             lea eax ,  dword ptr [ ebp + 0E8h ]
             push eax
             call  GetSystemDirectoryA
             lea eax ,  dword ptr [ ebp + 0E8h ]
             push eax
             call lstrlenA
             lea ecx ,  dword ptr [ ebp + 0E8h ]
             add eax , ecx
             cmp byte ptr [eax] , 05Ch
             je Labelc00aa54
             mov byte ptr [eax] , 05Ch
             mov byte ptr [eax+1] , 00h
             jmp Labelc00aa54


     Labelc00aa2f ::
             pushd 07h                                                       ;0x0c00aa2f :        6a07
             pop ecx                                                         ;0x0c00aa31 :        59
             mov edx , offset Datac41d558                                    ;0x0c00aa32 :        ba58d5410c
             call Func037004                                                 ;0x0c00aa37 :        e8c8c50200
             mov edi , eax                                                   ;0x0c00aa3c :        8bf8
             mov  ecx , dword ptr [edi]                                      ;0x0c00aa3e :        8b0f
             mov edx , ebx                                                   ;0x0c00aa40 :        8bd3
             lea eax ,  dword ptr [ ebp + 0E8h ]                             ;0x0c00aa42 :        8d85e8000000
             call Func02661c                                                 ;0x0c00aa48 :        e8cfbb0100
             mov ecx , edi                                                   ;0x0c00aa4d :        8bcf
             call Func02636a                                                 ;0x0c00aa4f :        e816b90100

     Labelc00aa54 ::
             mov  eax , dword ptr [ esi + offset Datac41afa0 ]                      ;0x0c00aa54 :        8b86a0af410c
             push  dword ptr [eax]                                           ;0x0c00aa5a :        ff30
             lea edi ,  dword ptr [ ebp + 0E8h ]                             ;0x0c00aa5c :        8dbde8000000
             call Func035ac3                                                 ;0x0c00aa62 :        e85cb00200
             mov edx , ebx                                                   ;0x0c00aa67 :        8bd3
             mov ecx , edi                                                   ;0x0c00aa69 :        8bcf
             call Func0356b0                                                 ;0x0c00aa6b :        e840ac0200
             mov  ecx , dword ptr [ esi + offset Datac41afa0 ]                      ;0x0c00aa70 :        8b8ea0af410c
             mov  dword ptr [ ebp - 52 ] , eax                               ;0x0c00aa76 :        8945cc
             call Func02636a                                                 ;0x0c00aa79 :        e8ecb80100
             xor edi , edi                                                   ;0x0c00aa7e :        33ff
             lea eax ,  dword ptr [ ebp + 0E8h ]                             ;0x0c00aa80 :        8d85e8000000
             mov  dword ptr [ esi + offset Datac41afa0 ] , edi                      ;0x0c00aa86 :        89bea0af410c
             mov  dword ptr [ esi + offset Datac41af98 ] , edi                      ;0x0c00aa8c :        89be98af410c
             call Func00ab3d                                                 ;0x0c00aa92 :        e8a6000000
             cmp  dword ptr [ DataPtrc414028 ] , edi                         ;0x0c00aa97 :        393d2840410c
             movzx eax ,byte ptr [eax]                                       ;0x0c00aa9d :        0fb600
             mov  dword ptr [ ebp - 48 ] , eax                               ;0x0c00aaa0 :        8945d0
             mov  dword ptr [ ebp - 40 ] , edi                               ;0x0c00aaa3 :        897dd8
             je Labelc00ab19                                                 ;0x0c00aaa6 :        7471

     Labelc00aaa8 ::
             lea edx ,  dword ptr [ ebp - 56 ]                               ;0x0c00aaa8 :        8d55c8
             lea eax ,  dword ptr [ ebp + 0FFFFFF74h ]                       ;0x0c00aaab :        8d8574ffffff
             call Func026303                                                 ;0x0c00aab1 :        e84db80100
             push edi                                                        ;0x0c00aab6 :        57
             push eax                                                        ;0x0c00aab7 :        50
             call Func0261a9                                                 ;0x0c00aab8 :        e8ecb60100
             mov  esi , dword ptr [ ebp - 40 ]                               ;0x0c00aabd :        8b75d8
             mov ebx , eax                                                   ;0x0c00aac0 :        8bd8
             cmp ebx , edi                                                   ;0x0c00aac2 :        3bdf
             pop ecx                                                         ;0x0c00aac4 :        59
             pop ecx                                                         ;0x0c00aac5 :        59
             jne Labelc00aaef                                                ;0x0c00aac6 :        7527
             push edi                                                        ;0x0c00aac8 :        57
             push edi                                                        ;0x0c00aac9 :        57
             push  dword ptr [ 4 * esi + offset DataPtrc414028 ]                    ;0x0c00aaca :        ff34b52840410c
             lea edx ,  dword ptr [ ebp + 0E8h ]                             ;0x0c00aad1 :        8d95e8000000
             push  dword ptr [ ebp - 52 ]                                    ;0x0c00aad7 :        ff75cc
             lea ecx ,  dword ptr [ ebp - 36 ]                               ;0x0c00aada :        8d4ddc
             call Func026746                                                 ;0x0c00aadd :        e864bc0100
             push edi                                                        ;0x0c00aae2 :        57
             lea eax ,  dword ptr [ ebp - 36 ]                               ;0x0c00aae3 :        8d45dc
             push eax                                                        ;0x0c00aae6 :        50
             call Func026b42                                                 ;0x0c00aae7 :        e856c00100
             mov  dword ptr [ ebp - 44 ] , eax                               ;0x0c00aaec :        8945d4

     Labelc00aaef ::
             lea eax ,  dword ptr [ ebp - 56 ]                               ;0x0c00aaef :        8d45c8
             push eax                                                        ;0x0c00aaf2 :        50
             lea eax ,  dword ptr [ ebp + 0FFFFFF74h ]                       ;0x0c00aaf3 :        8d8574ffffff
             call Func026342                                                 ;0x0c00aaf9 :        e844b80100
             cmp ebx , edi                                                   ;0x0c00aafe :        3bdf
             jne Labelc00ab07                                                ;0x0c00ab00 :        7505
             cmp  dword ptr [ ebp - 44 ] , edi                               ;0x0c00ab02 :        397dd4
             jne Labelc00ab6a                                                ;0x0c00ab05 :        7563

     Labelc00ab07 ::
             cmp  dword ptr [ ebp - 48 ] , edi                               ;0x0c00ab07 :        397dd0
             jne Labelc00ab19                                                ;0x0c00ab0a :        750d
             inc esi                                                         ;0x0c00ab0c :        46
             cmp  dword ptr [ 4 * esi + offset DataPtrc414028 ] , edi               ;0x0c00ab0d :        393cb52840410c
             mov  dword ptr [ ebp - 40 ] , esi                               ;0x0c00ab14 :        8975d8
             jne Labelc00aaa8                                                ;0x0c00ab17 :        758f


     ;
     ;                 --------------------------------------------------------------
     ;                      VFP 9.0 FIX - INITIALIZE THE REPORT SYSTEM VARIABLES
     ;                                  March 2024
     ;                 --------------------------------------------------------------
     ;                                     CCB
     ;
     ; Initialize the report system variables.
     ;
     ; 2024/3/3, by ccb
     ;

             cmp dword ptr [ ebp + 0200h ] , 26h
             je Labelc00ab18
             cmp dword ptr [ ebp + 0200h ] , 27h
             je Labelc00ab18
             cmp dword ptr [ ebp + 0200h ] , 45h
             je Labelc00ab18
             cmp dword ptr [ ebp + 0200h ] , 46h
             je Labelc00ab18
             cmp dword ptr [ ebp + 0200h ] , 55h
             je Labelc00ab18
             cmp dword ptr [ ebp + 0200h ] , 56h
             je Labelc00ab18
             cmp dword ptr [ ebp + 0200h ] , 57h
             je Labelc00ab18
             jmp Labelc00ab19

     Labelc00ab18 ::
             inc byte ptr [ ebp + 0E7h ]
             cmp byte ptr [ ebp + 0E7h ] , 02h
             ja Labelc00ab19
             jmp Labelc00a9ae


     Labelc00ab19 ::
             mov  ecx , dword ptr [ ebp + 01F4h ]                            ;0x0c00ab19 :        8b8df4010000
             call Func02619c                                                 ;0x0c00ab1f :        e878b60100
             pop edi                                                         ;0x0c00ab24 :        5f
             pop esi                                                         ;0x0c00ab25 :        5e
             pop ebx                                                         ;0x0c00ab26 :        5b
             add ebp , 01F8h                                                 ;0x0c00ab27 :        81c5f8010000
             leave                                                           ;0x0c00ab2d :        c9
             ret 04h                                                         ;0x0c00ab2e :        c20400


4. APPLIES TO:

     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.

     IMPORTANT NOTE:
     If the report application files (REPORTBUILDER.APP, REPORTPREVIEW.APP AND REPORTOUTPUT.APP) are in the application folder,
     recommend to add the following code to the main program:
     SET REPORTBEHAVIOR 90
     _REPORTBUILDER = FULLPATH("REPORTBUILDER.APP")
     _REPORTPREVIEW = FULLPATH("REPORTPREVIEW.APP")
     _REPORTOUTPUT = FULLPATH("REPORTOUTPUT.APP")


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfpsystemvariables.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix311.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix312.asp


6. OTHER:

     For reference only, there is no guarantees.

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