-----------------------------------------------------------------
                      VFP 9.0 FIX - THE SELECT UNION COMMAND WITH MEMO FIELDS
                                  March 2017
                 -----------------------------------------------------------------
                                    CCB



1. BUG:

     In vfp9 (and vfp7, vfp8), after we run the SELECT UNION command with memo fields,
     sometimes the memo file will be corrupted,
     vfp will occur the error memo file "name" is missing or is invalid (Error 41) when the table is accessed.

     The bug occurs in vfp7, vfp8 and vfp9, it does not occur in vfp6.

     The bug only occurs when SET("BLOCKSIZE")>1, it does not occur when SET("BLOCKSIZE")=1.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label42da0c ::
             mov  cl , byte ptr [ ebp - 35 ]                                 ;0x0042da0c :        8a4ddd
             mov  esi , dword ptr [ ebx + 36 ]                               ;0x0042da0f :        8b7324
             shl al , 03h                                                    ;0x0042da12 :        c0e003
             xor al , cl                                                     ;0x0042da15 :        32c1
             and al , 08h                                                    ;0x0042da17 :        2408
             xor cl , al                                                     ;0x0042da19 :        32c8
             cmp  dword ptr [ ebp - 24 ] , esi                               ;0x0042da1b :        3975e8
             mov  byte ptr [ ebp - 35 ] , cl                                 ;0x0042da1e :        884ddd
             jne Label56e2b4                                                 ;0x0042da21 :        0f858d081400


     ;
     ;                 -----------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE SELECT UNION COMMAND WITH MEMO FIELDS
     ;                                  March 2017
     ;                 -----------------------------------------------------------------
     ;                                     CCB
     ;
     ; After we run the SELECT UNION command with memo fields,
     ; sometimes the memo file will be corrupted (memo file "name" is missing or is invalid).
     ;
     ; 2017/3/12, by ccb
     ;

             cmp dword ptr vfpa_selectunion_isselect,00h
             je Label42da27
             mov edi , dword ptr [ ebp - 16 ]
             test edi , edi
             jle Label42da27
             mov eax , dword ptr [ ebx + 16 ]
             mov ecx , dword ptr [eax]
             lea edi , dword ptr [ ecx + 4 * edi ]
             mov edx , dword ptr [ ebx + 20 ]
             mov eax , dword ptr [ edi - 4 ]
             add eax , dword ptr [edx]
             mov ecx , dword ptr [ eax + 8 ]
             cmp dword ptr [ eax + 12 ] , ecx
             jae Label42da27
             mov dword ptr [ eax + 12 ] , ecx


     Label42da27 ::
             mov  eax , dword ptr [ ebp - 16 ]                               ;0x0042da27 :        8b45f0

     Label42da2a ::
             mov  ecx , dword ptr [ ebx + 16 ]                               ;0x0042da2a :        8b4b10
             mov  edx , dword ptr [ecx]                                      ;0x0042da2d :        8b11
             sub esi , eax                                                   ;0x0042da2f :        2bf0
             lea edi ,  dword ptr [ edx + 4 * eax ]                          ;0x0042da31 :        8d3c82
             shl esi , 02h                                                   ;0x0042da34 :        c1e602
             push esi                                                        ;0x0042da37 :        56
             lea ecx ,  dword ptr [ edi + 4 ]                                ;0x0042da38 :        8d4f04
             mov edx , edi                                                   ;0x0042da3b :        8bd7
             call Fun42c19b                                                  ;0x0042da3d :        e859e7ffff
             mov  eax , dword ptr [ ebx + 24 ]                               ;0x0042da42 :        8b4318
             mov  dword ptr [edi] , eax                                      ;0x0042da45 :        8907
             mov  ecx , dword ptr [ ebx + 20 ]                               ;0x0042da47 :        8b4b14
             mov  eax , dword ptr [ecx]                                      ;0x0042da4a :        8b01
             mov  edx , dword ptr [ ebx + 24 ]                               ;0x0042da4c :        8b5318
             mov  ecx , dword ptr [ ebx + 36 ]                               ;0x0042da4f :        8b4b24
             add eax , edx                                                   ;0x0042da52 :        03c2
             mov  edx , dword ptr [eax]                                      ;0x0042da54 :        8b10
             inc ecx                                                         ;0x0042da56 :        41
             mov  dword ptr [ ebx + 36 ] , ecx                               ;0x0042da57 :        894b24
             mov  ecx , dword ptr [ ebp - 16 ]                               ;0x0042da5a :        8b4df0
             mov  dword ptr [ ebx + 32 ] , ecx                               ;0x0042da5d :        894b20
             mov  ecx , dword ptr [ ebp - 56 ]                               ;0x0042da60 :        8b4dc8
             mov  dword ptr [ ebx + 24 ] , edx                               ;0x0042da63 :        895318
             mov edx , eax                                                   ;0x0042da66 :        8bd0
             mov  dword ptr [edx] , ecx                                      ;0x0042da68 :        890a
             mov  ecx , dword ptr [ ebp - 52 ]                               ;0x0042da6a :        8b4dcc
             mov  dword ptr [ edx + 4 ] , ecx                                ;0x0042da6d :        894a04
             mov  ecx , dword ptr [ ebp - 48 ]                               ;0x0042da70 :        8b4dd0
             mov  dword ptr [ edx + 8 ] , ecx                                ;0x0042da73 :        894a08
             mov  ecx , dword ptr [ ebp - 44 ]                               ;0x0042da76 :        8b4dd4
             mov  dword ptr [ edx + 12 ] , ecx                               ;0x0042da79 :        894a0c
             mov  ecx , dword ptr [ ebp - 40 ]                               ;0x0042da7c :        8b4dd8
             pop edi                                                         ;0x0042da7f :        5f
             mov  dword ptr [ edx + 16 ] , ecx                               ;0x0042da80 :        894a10
             mov  ecx , dword ptr [ ebp - 36 ]                               ;0x0042da83 :        8b4ddc
             pop esi                                                         ;0x0042da86 :        5e
             mov  dword ptr [ edx + 20 ] , ecx                               ;0x0042da87 :        894a14
             pop ebx                                                         ;0x0042da8a :        5b
             mov esp , ebp                                                   ;0x0042da8b :        8be5
             pop ebp                                                         ;0x0042da8d :        5d
             ret 04h                                                         ;0x0042da8e :        c20400


4. APPLIES TO:

     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

     2, microsoft.com:
     https://social.msdn.microsoft.com/Forums/en-US/3413009d-17b1-4ae3-9b26-c7eeed230f13/memo-file-missing-or-is-invalid-after-select-union

     3, tek-tips.com:
     http://www.tek-tips.com/viewthread.cfm?qid=1641620


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please e-mail to ccb2000@163.com.