In some code I'm maintaining, I see two different methods used in `TClientDataSet.OnCalcFields` event handlers:

```
 with DataSet do
 begin
   // 1. Call FieldByName twice
   if AMinDate > FieldByName(SPlanAllocatieFromDate).AsDateTime then
      AMinDate := FieldByName(sPlanAllocatieFromDate).AsDateTime;
   // 2. Put the retrieved FieldByName value in a temp var
   lEmpID := FieldByName(SPlanAllocatieEmpID).AsInteger;
   if lEmpID <> 0 then lTSAllocatedEmpIDs.Add(IntToStr(lEmpID));
 end;

```

Will the compiler (Delphi XE2, Win32 app) optimize method 2 to use a temp var? The two FieldByNames are quite close, you could even say *nested*.

If not, I should rewrite 1. because OnCalcFields executes often.

BTW. I know about Fields[] versus FieldByName(), or using a temp TField var when running an EOF loop, those are not the issue here.