

LastICO:LongInt
LastDate:Word
LastDokl:String[10];
Veta:LongInt
VetaA:LongInt

DeclareRec('Adresar');
DeclareRec('KeyAdresar1');
DeclareRec('Pohledavka');
DeclareRec('KeyPohledavka3');

ClearRec(KeyPohledavka3);
While(NextKey(KeyPohledavka3,Veta))
  begin
    ReadRec(Pohledavka,Veta);
    if(LastICO<>Pohledavka.ICO)
      begin
        if(LastICO<>0)
          begin
            KeyAdresar1.Length=4
            KeyAdresar1.ICO=SwapL(LastICO)
            if(FindKey(KeyAdresar1,VetaA))
              begin
                ReadRec(Adresar,VetaA);
                if(LastDate>Adresar.LastUseDate_pohl)
                  begin
                    Adresar.LastUseDate_pohl=LastDate;
                    Adresar.LastUseDokl_pohl=LastDokl;
                    ModifyRec(Adresar,VetaA)
                  end;
              end
          end;
        LastICO=Pohledavka.ICO
        LastDate=Pohledavka.Datum
        LastDokl=Pohledavka.Doklad
      end
    if(Pohledavka.Datum>LastDate)
      begin
        LastDate=Pohledavka.Datum
        LastDokl=Pohledavka.Doklad
      end
  end

END