title: Delphi out of memory error when i load file to memory stream
body: <p>I want to convert a 2GB file to an array of byte with Delphi. I use this function, then load file into memory Stream to get bytes. But I get error "Out of memory". How I can solve this problem?</p>
  
  <pre><code>type
  TByteArray  =  Array of Byte;
  
  function StreamToByteArray(Stream: TStream): TByteArray;
  begin
  
  // Check stream
  if Assigned(Stream) then
  begin
  // Reset stream position
  Stream.Position:=0;
  // Allocate size
  SetLength(result, Stream.Size);
  // Read contents of stream
  Stream.Read(result[0], Stream.Size);
  end
  else
  // Clear result
  SetLength(result, 0);
  end;
  //////then in button control i use:
  var
  strmMem: TMemoryStream;
  bytes: TByteArray;
  begin
  strmMem:=TMemoryStream.Create;
  if OpenDialog1.Execute then
  strmMem.LoadFromFile(OpenDialog1.FileName);
  bytes:=StreamToByteArray(strmMem);
  strmMem.Free;
  </code></pre>