procedure SaveBufToFile(ABuf: string; const AFileName: string);
begin
  with TStringList.Create do
  try
    Add(ABuf);
    SaveToFile(AFileName)
  finally
    Free
  end;
end;function SubBuf2Str(const AVarArr: Variant; const
AIndex, ALen: Integer): string;
var
  i: Integer;
begin
  SetLength(Result, ALen);
  for i := 1 to ALen do
    Result[i] := Chr(Byte(AVarArr[i + AIndex - 1]));
end;