replace with for in Foxpro

2.5k views Asked by At

I am reverse engineering a program made in FoxPro.

I know nothing of FoxPro, fortunately the program is simple and more or less I could understand all processes

I have this, in the source code

Select 1
SET RELATION TO GROUP_T+POL INTO BASE2
REPLACE MARK_T WITH BASE2->STATUS FOR GROUP_T+POL=BASE2->GROUP_T+POL
REPLACE LAPSE2 WITH BASE2->LAPSE FOR GROUP_T+POL=BASE2->GROUP_T+POL
REPLACE STATUS2 WITH BASE2->STATUS FOR GROUP_T+POL=BASE2->GROUP_T+POL
REPLACE DATPAHAS2 WITH BASE2->DATPAHAS FOR GROUP_T+POL=BASE2->GROUP_T+POL
CLOSE DATABASES

I need to know from where the variable LAPSE2 this is used later.

But i donĀ“t know as calculated

What does this mean?

REPLACE LAPSE2 WITH BASE2->LAPSE FOR GROUP_T+POL=BASE2->GROUP_T+POL

This is the only line that appears before use later in a condition

1

There are 1 answers

0
DarthGizka On BEST ANSWER

In the fragment that you showed, the value of each LAPSE2 in the current table is replaced with the value of the LAPSE field of the first matching record in BASE2, based on the index currently set in that table.

The FOR clause restricts this to records that do have matching records in BASE2; unmatched records are skipped (remain unchanged). Without this filter the new value for LAPSE2 would be an empty value ('', .f., 0, ...) when there is no matching record.

Note: a REPLACE without any FOR or WHILE would affect only a single record, since the absence of a scope clause implies NEXT 1 (another way of looking at it would be that FOR sort of implies ALL and WHILE sort of implies REST).

The SET RELATION statement at the beginning of the code fragment causes Fox to perform a seek in the BASE2 table with the result of evaluating the expression GROUP_T+POL whenever the record pointer changes. Put differently: whenever the record pointer is moved in the master table, the record pointer in the child table(s) is moved to the first matching record (if any) or to EOF if there are no matches.

Hence the combination of SET RELATION with REPLACE ... FOR <key match> is similar to

replace LAPSE2 with Base2.LAPSE for seek(GROUP_T + POL, [Base2])

Note: this statement is only intended to illustrate what happens; it should never be used in actual code because it is fraught with problems and bugs.