/* LIST / DISPLAY TO FILE — text output redirected to a file. */ PROCEDURE Main() LOCAL aStruct, cBuf, e FErase("p.dbf") FErase("out.txt") aStruct := { ; { "ID", "N", 4, 0 }, ; { "NAME", "C", 10, 0 }, ; { "AGE", "N", 3, 0 } } dbCreate("p.dbf", aStruct) USE p.dbf NEW EXCLUSIVE ALIAS p dbAppend(); FieldPut(1,1); FieldPut(2,"Alice"); FieldPut(3,18) dbAppend(); FieldPut(1,2); FieldPut(2,"Bob"); FieldPut(3,25) dbAppend(); FieldPut(1,3); FieldPut(2,"Carol"); FieldPut(3,30) dbCommit() /* 1. LIST TO FILE — full table */ dbGoTop() LIST TO FILE out.txt cBuf := MemoRead("out.txt") ? "1. file size:", Len(cBuf), "bytes (expect > 0)" IF Len(cBuf) == 0 ? "FAIL: empty output file" RETURN ENDIF ? "1. file content:" ? cBuf /* 2. DISPLAY TO FILE — single record */ FErase("out.txt") dbGoto(2) DISPLAY TO FILE out.txt cBuf := MemoRead("out.txt") ? "2. DISPLAY single-row file:" ? cBuf IF !("Bob" $ cBuf) ? "FAIL: Bob row missing" RETURN ENDIF /* 3. LIST TO FILE with OFF + FOR — std.ch pattern order is `[] [FOR ]`, same as Harbour. */ FErase("out.txt") dbGoTop() LIST p->id, p->name TO FILE out.txt OFF FOR p->age >= 25 cBuf := MemoRead("out.txt") ? "3. selective+OFF file:" ? cBuf IF "Alice" $ cBuf ? "FAIL: Alice (age 18) shouldn't be in FOR age>=25 output" RETURN ENDIF /* 4. TO PRINTER — should still reject */ e := .F. BEGIN SEQUENCE LIST TO PRINTER RECOVER e := .T. END SEQUENCE ? "4. TO PRINTER rejected:", e, "(expect .T.)" dbCloseArea() FErase("p.dbf") FErase("out.txt") ? "DONE" RETURN