-------------------------------------------------------------------------------------------------
                      VFP 9.0 FIX - THE COMPILE DATABASE COMMAND COMPILES DATABASE FILES INTO NEW FILE FORMAT
                                   May 2020
                 -------------------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     If we enable the COMPILE DATABASE command to compile database files into new file format,
     and there are some stored procedures in the database files, the compiled database files can only be opened in Visual FoxPro Advanced.
     When we open the compiled database files in Visual FoxPro 9.0 or Visual FoxPro earlier versions,
     it will occur an error: Object file "name" was compiled in a different version of FoxPro (Error 1195).
     We can run the COMPILE DATABASE command in Visual FoxPro 9.0 or Visual FoxPro earlier versions to solve the problem.

     If we disable the COMPILE DATABASE command to compile database files into new file format,
     the compiled database files can be opened in Visual FoxPro all versions (Visual FoxPro Advanced and Visual FoxPro earlier versions).
     It is the startup default for Visual FoxPro Advanced.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun54814b :: ; proc near
             push ebp                                                        ;0x0054814b :        55
             mov ebp , esp                                                   ;0x0054814c :        8bec
             sub esp , 0114h                                                 ;0x0054814e :        81ec14010000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x00548154 :        a190709300
             mov  dword ptr [ ebp - 4 ] , eax                                ;0x00548159 :        8945fc
             mov eax ,  dword ptr [ Data9388f0 ]                             ;0x0054815c :        a1f0889300
             mov  ecx , dword ptr [ eax + 0268h ]                            ;0x00548161 :        8b8868020000
             test  byte ptr [ ecx + 12 ] , 01h                               ;0x00548167 :        f6410c01
             push esi                                                        ;0x0054816b :        56
             jne Label548443                                                 ;0x0054816c :        0f85d1020000
             lea ecx ,  dword ptr [ eax + 0294h ]                            ;0x00548172 :        8d8894020000
             xor esi , esi                                                   ;0x00548178 :        33f6
             cmp  dword ptr [ecx] , esi                                      ;0x0054817a :        3931
             push edi                                                        ;0x0054817c :        57
             mov  edi , dword ptr [ ebp + 12 ]                               ;0x0054817d :        8b7d0c
             jne Label462929                                                 ;0x00548180 :        0f85a3a7f1ff

     Label548186 ::
             mov  ax , word ptr [ eax + 02E4h ]                              ;0x00548186 :        668b80e4020000
             mov  word ptr [ edi + 2 ] , ax                                  ;0x0054818d :        66894702
             call Fun547db1                                                  ;0x00548191 :        e81bfcffff
             mov  dword ptr [ edi + 12 ] , eax                               ;0x00548196 :        89470c
             mov eax ,  dword ptr [ Data9388f0 ]                             ;0x00548199 :        a1f0889300
             mov  eax , dword ptr [ eax + 0268h ]                            ;0x0054819e :        8b8068020000
             test  byte ptr [ eax + 8 ] , 04h                                ;0x005481a4 :        f6400804
             jne Label5481b4                                                 ;0x005481a8 :        750a
             call Fun548092                                                  ;0x005481aa :        e8e3feffff
             call Fun547df8                                                  ;0x005481af :        e844fcffff

     Label5481b4 ::
             pushd 02h                                                       ;0x005481b4 :        6a02
             mov edx , offset Data92010c                                              ;0x005481b6 :        ba0c019200
             mov ecx , ebx                                                   ;0x005481bb :        8bcb
             call Fun42c19b                                                  ;0x005481bd :        e8d93feeff
             mov  al , byte ptr [ ebp + 16 ]                                 ;0x005481c2 :        8a4510
             mov  ecx , dword ptr [ Data9388f0 ]                             ;0x005481c5 :        8b0df0889300
             not al                                                          ;0x005481cb :        f6d0
             mov  byte ptr [ edi + 36 ] , al                                 ;0x005481cd :        884724
             lea eax ,  dword ptr [ ebp + 16 ]                               ;0x005481d0 :        8d4510
             mov  word ptr [ ebx + 3 ] , 0220h                               ;0x005481d3 :        66c743032002


     ;
     ;                 -------------------------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE COMPILE DATABASE COMMAND COMPILES DATABASE FILES INTO NEW FILE FORMAT
     ;                                   May 2020
     ;                 -------------------------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; The COMPILE DATABASE command compiles database files into new file format.
     ;
     ; 2020/5/23, by ccb
     ;

             push ecx
             push eax
             push dword ptr [ Data9388f0 ]
             call vfpa_isdbcfile
             test eax,eax
             pop eax
             pop ecx
             je Label5481d8
             cmp dword ptr vfpa_sys9032_data,00h
             jne Label5481d8
             jmp Label5481d9
     Label5481d8 ::
             mov  word ptr [ ebx + 3 ] , 0222h


     Label5481d9 ::
             mov  byte ptr [ ebx + 2 ] , 0FFh                                ;0x005481d9 :        c64302ff
             push eax                                                        ;0x005481dd :        50
             add ecx , 0224h                                                 ;0x005481de :        81c124020000
             mov  dword ptr [ edi + 4 ] , 025h                               ;0x005481e4 :        c7470425000000
             mov  dword ptr [ ebp + 16 ] , esi                               ;0x005481eb :        897510
             call Fun547e73                                                  ;0x005481ee :        e880fcffff
             mov  eax , dword ptr [ ebp + 16 ]                               ;0x005481f3 :        8b4510
             mov  dword ptr [ edi + 28 ] , eax                               ;0x005481f6 :        89471c
             mov eax ,  dword ptr [ Data9388f0 ]                             ;0x005481f9 :        a1f0889300
             mov  word ptr [ ebx + 7 ] , si                                  ;0x005481fe :        66897307
             mov  esi , dword ptr [ ebp + 8 ]                                ;0x00548202 :        8b7508
             add eax , 0244h                                                 ;0x00548205 :        0544020000
             mov  byte ptr [esi] , 00h                                       ;0x0054820a :        c60600
             mov  dword ptr [ esi + 1 ] , 029h                               ;0x0054820d :        c7460129000000
             call Fun546c68                                                  ;0x00548214 :        e84feaffff
             and  dword ptr [ esi + 9 ] , 00h                                ;0x00548219 :        83660900
             mov  dword ptr [ esi + 5 ] , eax                                ;0x0054821d :        894605
             mov eax ,  dword ptr [ Data9388f0 ]                             ;0x00548220 :        a1f0889300
             add eax , 0244h                                                 ;0x00548225 :        0544020000
             call Fun546c68                                                  ;0x0054822a :        e839eaffff
             mov  ecx , dword ptr [ Data9388f0 ]                             ;0x0054822f :        8b0df0889300
             mov  dword ptr [ ebx + 13 ] , eax                               ;0x00548235 :        89430d
             cmp  dword ptr [ ecx + 0218h ] , 00h                            ;0x00548238 :        83b91802000000
             jne Label54830a                                                 ;0x0054823f :        0f85c5000000
             add ecx , 0105h                                                 ;0x00548245 :        81c105010000
             push ecx                                                        ;0x0054824b :        51
             lea eax ,  dword ptr [ ebp + 0FFFFFEECh ]                       ;0x0054824c :        8d85ecfeffff
             push eax                                                        ;0x00548252 :        50
             call Fun434bcf                                                  ;0x00548253 :        e877c9eeff
             pushd 07h                                                       ;0x00548258 :        6a07
             pop ecx                                                         ;0x0054825a :        59
             lea edx ,  dword ptr [ ebp + 0FFFFFEECh ]                       ;0x0054825b :        8d95ecfeffff
             call Fun433395                                                  ;0x00548261 :        e82fb1eeff
             mov  esi , dword ptr [eax]                                      ;0x00548266 :        8b30
             mov  dword ptr [ ebp + 0FFFFFEF0h ] , eax                       ;0x00548268 :        8985f0feffff
             mov eax , esi                                                   ;0x0054826e :        8bc6
             lea edi ,  dword ptr [ eax + 1 ]                                ;0x00548270 :        8d7801

     Label548273 ::
             mov  cl , byte ptr [eax]                                        ;0x00548273 :        8a08
             inc eax                                                         ;0x00548275 :        40
             test cl , cl                                                    ;0x00548276 :        84c9
             jne Label548273                                                 ;0x00548278 :        75f9
             sub eax , edi                                                   ;0x0054827a :        2bc7
             inc eax                                                         ;0x0054827c :        40
             movzx edi , ax                                                  ;0x0054827d :        0fb7f8
             push edi                                                        ;0x00548280 :        57
             push esi                                                        ;0x00548281 :        56
             mov  esi , dword ptr [ Data9388f0 ]                             ;0x00548282 :        8b35f0889300
             add esi , 0244h                                                 ;0x00548288 :        81c644020000
             mov  dword ptr [ ebp + 16 ] , eax                               ;0x0054828e :        894510
             call Fun546c80                                                  ;0x00548291 :        e8eae9ffff
             mov  ecx , dword ptr [ ebp + 0FFFFFEF0h ]                       ;0x00548296 :        8b8df0feffff
             call Fun42c1e2                                                  ;0x0054829c :        e8413feeff
             mov  eax , dword ptr [ ebp + 8 ]                                ;0x005482a1 :        8b4508
             mov  ecx , dword ptr [ Data9388f0 ]                             ;0x005482a4 :        8b0df0889300
             mov  dword ptr [ eax + 13 ] , edi                               ;0x005482aa :        89780d
             xor edi , edi                                                   ;0x005482ad :        33ff
             inc edi                                                         ;0x005482af :        47
             add ecx , 0105h                                                 ;0x005482b0 :        81c105010000
             mov eax , edi                                                   ;0x005482b6 :        8bc7
             lea edx ,  dword ptr [ ebp + 0FFFFFEF4h ]                       ;0x005482b8 :        8d95f4feffff
             call Fun43f2b9                                                  ;0x005482be :        e8f66fefff
             xor esi , esi                                                   ;0x005482c3 :        33f6

     Label5482c5 ::
             cmp  byte ptr [ ebp + esi + 0FFFFFEF4h ] , 00h                  ;0x005482c5 :        80bc35f4feffff00
             je Label5482d8                                                  ;0x005482cd :        7409
             inc esi                                                         ;0x005482cf :        46
             cmp esi , 0106h                                                 ;0x005482d0 :        81fe06010000
             jl Label5482c5                                                  ;0x005482d6 :        7ced

     Label5482d8 ::
             cmp esi , 0106h                                                 ;0x005482d8 :        81fe06010000
             jnl Label566a77                                                 ;0x005482de :        0f8d93e70100

     Label5482e4 ::
             inc esi                                                         ;0x005482e4 :        46
             push esi                                                        ;0x005482e5 :        56
             mov  esi , dword ptr [ Data9388f0 ]                             ;0x005482e6 :        8b35f0889300
             lea eax ,  dword ptr [ ebp + 0FFFFFEF4h ]                       ;0x005482ec :        8d85f4feffff
             push eax                                                        ;0x005482f2 :        50
             add esi , 0244h                                                 ;0x005482f3 :        81c644020000
             call Fun546c80                                                  ;0x005482f9 :        e882e9ffff
             mov  ecx , dword ptr [ Data9388f0 ]                             ;0x005482fe :        8b0df0889300
             mov  edi , dword ptr [ ebp + 12 ]                               ;0x00548304 :        8b7d0c
             mov  esi , dword ptr [ ebp + 8 ]                                ;0x00548307 :        8b7508

     Label54830a ::
             mov  eax , dword ptr [ ecx + 0268h ]                            ;0x0054830a :        8b8168020000
             test  byte ptr [ eax + 8 ] , 04h                                ;0x00548310 :        f6400804
             jne Label5483b7                                                 ;0x00548314 :        0f859d000000
             cmp  dword ptr [ ecx + 0218h ] , 00h                            ;0x0054831a :        83b91802000000
             jne Label548394                                                 ;0x00548321 :        7571
             xor esi , esi                                                   ;0x00548323 :        33f6

     Label548325 ::
             cmp  byte ptr [ ebp + esi + 0FFFFFEF4h ] , 00h                  ;0x00548325 :        80bc35f4feffff00
             je Label548338                                                  ;0x0054832d :        7409
             inc esi                                                         ;0x0054832f :        46
             cmp esi , 0106h                                                 ;0x00548330 :        81fe06010000
             jl Label548325                                                  ;0x00548336 :        7ced

     Label548338 ::
             cmp esi , 0106h                                                 ;0x00548338 :        81fe06010000
             jnl Label566a83                                                 ;0x0054833e :        0f8d3fe70100

     Label548344 ::
             movzx eax ,word ptr [ ebp + 16 ]                                ;0x00548344 :        0fb74510
             lea eax ,  dword ptr [ esi + eax + 1 ]                          ;0x00548348 :        8d440601
             xor edx , edx                                                   ;0x0054834c :        33d2
             mov  dword ptr [ edi + 32 ] , eax                               ;0x0054834e :        894720
             call Fun43d2bf                                                  ;0x00548351 :        e8694fefff
             mov  esi , dword ptr [eax]                                      ;0x00548356 :        8b30
             mov  dword ptr [ ebp + 0FFFFFEF0h ] , eax                       ;0x00548358 :        8985f0feffff
             mov eax , esi                                                   ;0x0054835e :        8bc6
             lea ecx ,  dword ptr [ eax + 1 ]                                ;0x00548360 :        8d4801

     Label548363 ::
             mov  dl , byte ptr [eax]                                        ;0x00548363 :        8a10
             inc eax                                                         ;0x00548365 :        40
             test dl , dl                                                    ;0x00548366 :        84d2
             jne Label548363                                                 ;0x00548368 :        75f9
             sub eax , ecx                                                   ;0x0054836a :        2bc1
             inc eax                                                         ;0x0054836c :        40
             push eax                                                        ;0x0054836d :        50
             push esi                                                        ;0x0054836e :        56
             mov  esi , dword ptr [ Data9388f0 ]                             ;0x0054836f :        8b35f0889300
             add esi , 0244h                                                 ;0x00548375 :        81c644020000
             call Fun546c80                                                  ;0x0054837b :        e800e9ffff
             mov  ecx , dword ptr [ ebp + 0FFFFFEF0h ]                       ;0x00548380 :        8b8df0feffff
             call Fun42c1e2                                                  ;0x00548386 :        e8573eeeff
             mov  ecx , dword ptr [ Data9388f0 ]                             ;0x0054838b :        8b0df0889300
             mov  esi , dword ptr [ ebp + 8 ]                                ;0x00548391 :        8b7508

     Label548394 ::
             mov  eax , dword ptr [ ecx + 026Ch ]                            ;0x00548394 :        8b816c020000
             mov  dword ptr [ edi + 24 ] , eax                               ;0x0054839a :        894718
             mov  edx , dword ptr [ ecx + 02B8h ]                            ;0x0054839d :        8b91b8020000
             mov  eax , dword ptr [ ecx + 02C8h ]                            ;0x005483a3 :        8b81c8020000
             add eax , edx                                                   ;0x005483a9 :        03c2
             mov  edx , dword ptr [ edi + 24 ]                               ;0x005483ab :        8b5718
             mov  dword ptr [ edi + 20 ] , eax                               ;0x005483ae :        894714
             lea eax ,  dword ptr [ edx + 2 * eax ]                          ;0x005483b1 :        8d0442
             mov  dword ptr [ edi + 16 ] , eax                               ;0x005483b4 :        894710

     Label5483b7 ::
             lea eax ,  dword ptr [ ecx + 0244h ]                            ;0x005483b7 :        8d8144020000
             call Fun546c68                                                  ;0x005483bd :        e8a6e8ffff
             sub  eax , dword ptr [ ebx + 13 ]                               ;0x005483c2 :        2b430d
             mov  word ptr [ ebx + 5 ] , 01h                                 ;0x005483c5 :        66c743050100
             mov  dword ptr [ ebx + 17 ] , eax                               ;0x005483cb :        894311
             mov eax ,  dword ptr [ Data9388f0 ]                             ;0x005483ce :        a1f0889300
             add eax , 0244h                                                 ;0x005483d3 :        0544020000
             call Fun546c68                                                  ;0x005483d8 :        e88be8ffff
             pushd 019h                                                      ;0x005483dd :        6a19
             push esi                                                        ;0x005483df :        56
             mov  esi , dword ptr [ Data9388f0 ]                             ;0x005483e0 :        8b35f0889300
             add esi , 0244h                                                 ;0x005483e6 :        81c644020000
             mov  dword ptr [ ebx + 9 ] , eax                                ;0x005483ec :        894309
             call Fun546c80                                                  ;0x005483ef :        e88ce8ffff
             mov  esi , dword ptr [ Data9388f0 ]                             ;0x005483f4 :        8b35f0889300
             mov  eax , dword ptr [ ebp + 8 ]                                ;0x005483fa :        8b4508
             mov  ecx , dword ptr [ eax + 1 ]                                ;0x005483fd :        8b4801
             add esi , 0244h                                                 ;0x00548400 :        81c644020000
             mov eax , esi                                                   ;0x00548406 :        8bc6
             call Fun5476b6                                                  ;0x00548408 :        e8a9f2ffff
             pushd 025h                                                      ;0x0054840d :        6a25
             push edi                                                        ;0x0054840f :        57
             call Fun546c80                                                  ;0x00548410 :        e86be8ffff
             mov  esi , dword ptr [ Data9388f0 ]                             ;0x00548415 :        8b35f0889300
             add esi , 0244h                                                 ;0x0054841b :        81c644020000
             xor ecx , ecx                                                   ;0x00548421 :        33c9
             mov eax , esi                                                   ;0x00548423 :        8bc6
             call Fun5476b6                                                  ;0x00548425 :        e88cf2ffff
             mov eax , ebx                                                   ;0x0054842a :        8bc3
             call Fun548481                                                  ;0x0054842c :        e850000000
             pushd 029h                                                      ;0x00548431 :        6a29
             push ebx                                                        ;0x00548433 :        53
             mov  word ptr [ ebx + 39 ] , ax                                 ;0x00548434 :        66894327
             call Fun546c80                                                  ;0x00548438 :        e843e8ffff
             mov eax ,  dword ptr [ Data9388f0 ]                             ;0x0054843d :        a1f0889300
             pop edi                                                         ;0x00548442 :        5f

     Label548443 ::
             lea ecx ,  dword ptr [ eax + 0268h ]                            ;0x00548443 :        8d8868020000
             mov  edx , dword ptr [ecx]                                      ;0x00548449 :        8b11
             mov  dword ptr [ edx + 56 ] , 01h                               ;0x0054844b :        c7423801000000
             mov  edx , dword ptr [ eax + 0294h ]                            ;0x00548452 :        8b9094020000
             mov  esi , dword ptr [ecx]                                      ;0x00548458 :        8b31
             inc edx                                                         ;0x0054845a :        42
             mov  dword ptr [ esi + 64 ] , edx                               ;0x0054845b :        895640
             mov  edx , dword ptr [ecx]                                      ;0x0054845e :        8b11
             mov  esi , dword ptr [ eax + 02E4h ]                            ;0x00548460 :        8bb0e4020000
             mov  dword ptr [ edx + 68 ] , esi                               ;0x00548466 :        897244
             mov  ecx , dword ptr [ecx]                                      ;0x00548469 :        8b09
             mov  eax , dword ptr [ eax + 0290h ]                            ;0x0054846b :        8b8090020000
             mov  dword ptr [ ecx + 72 ] , eax                               ;0x00548471 :        894148
             mov  ecx , dword ptr [ ebp - 4 ]                                ;0x00548474 :        8b4dfc
             pop esi                                                         ;0x00548477 :        5e
             call Fun42bf1d                                                  ;0x00548478 :        e8a03aeeff
             leave                                                           ;0x0054847d :        c9
             ret 0Ch                                                         ;0x0054847e :        c20c00


4. APPLIES TO:

     VFP 10.0.0.0 (VFP Advanced)


5. REFERENCE WEBSITES:

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


6. OTHER:

     For reference only, there is no guarantees.

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