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
In the fragment that you showed, the value of each
LAPSE2
in the current table is replaced with the value of theLAPSE
field of the first matching record inBASE2
, based on the index currently set in that table.The
FOR
clause restricts this to records that do have matching records inBASE2
; unmatched records are skipped (remain unchanged). Without this filter the new value forLAPSE2
would be an empty value ('', .f., 0, ...) when there is no matching record.Note: a
REPLACE
without anyFOR
orWHILE
would affect only a single record, since the absence of a scope clause impliesNEXT 1
(another way of looking at it would be thatFOR
sort of impliesALL
andWHILE
sort of impliesREST
).The
SET RELATION
statement at the beginning of the code fragment causes Fox to perform a seek in theBASE2
table with the result of evaluating the expressionGROUP_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
withREPLACE ... FOR <key match>
is similar toNote: 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.