title: stuck with streaming file to string
body: <p>okay, so I (VERY) recently started playing with lazaruz/free pascal, and I'm a little stuck with reading files with TMemoryStream and it's streaming kin.</p>
  
  <p>I'm trying to write a simple base64 encoder, that can encode strings of text, or files (like images and WAVs) to then be used in html and javascript.</p>
  
  <p>The following code compiles great but I get <code>EReadError Illegal stream image</code> when trying to load a file. I'll include the working string only procedure for reference:</p>
  
  <pre><code>procedure TForm1.TextStringChange(Sender: TObject);
      begin
      Memo1.Lines.Text := EncodeStringBase64(TextString.Text);
  end;
  
  procedure TForm1.FormCreate(Sender: TObject);
  begin
     Memo1.Lines.Text := '';
     Form1.BorderIcons :=  [biSystemMenu,biMinimize];
  end;
  
  procedure TForm1.BitBtn1Click(Sender: TObject);
  begin
      if OpenDialog1.Execute then
      begin
       filename := OpenDialog1.Filename;
       stream := TMemoryStream.Create;
         try
           StrStream := TStringStream.Create(s);
             try
                stream.LoadFromFile(filename);
                stream.Seek(0, soFromBeginning);
                ObjectBinaryToText(stream, StrStream);
                StrStream.Seek(0, soFromBeginning);
                Memo1.Lines.Text := EncodeStringBase64(StrStream.DataString);
             finally
                StrStream.Free;
             end;
         finally
             stream.Free;
         end;
      end;
  end;   
  </code></pre>
  
  <p>Can anyone help me out?</p>