Anti-Patterns: Common Mistakes to Avoid
Anti-Pattern 1: Processing All Records Every Time
The Mistake
// ❌ WRONG: No filter on processed records
if MyTable.FindSet(true) then
repeat
if MyTable."Status" <> 'PROCESSED' then begin // Checked 2.5M times!
MyTable."Status" := 'PROCESSED';
MyTable.Modify();
end;
until MyTable.Next() = 0;
Why It's Bad
- Loads ALL 2.5M records into memory
- Evaluates IF condition 2.5M times
- Wastes time on already-processed records
- No benefit from batch limiting (reprocesses everything)
The Fix
// ✅ CORRECT: Filter before loading
MyTable.SetFilter("Status", '<>%1', 'PROCESSED'); // DB-level filter
if MyTable.FindSet(true) then
repeat
MyTable."Status" := 'PROCESSED';
MyTable.Modify(false);
until MyTable.Next() = 0;
Impact
| Approach | Records Loaded | Time (50K records) |
|---|---|---|
| Wrong (no filter) | 2,500,000 | 45 minutes |
| Correct (filtered) | 50,000 | 12 minutes |