unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdCoder3To4, IdBaseComponent, IdCoder;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
IdBase64Encoder1: TIdBase64Encoder;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MyFileStream :TFileStream;
Buffer :String;
begin
try
MyFileStream:=TFileStream.Create('banner.gif',fmOpenRead);
SetLength(buffer, MyFileStream.Size);
MyFileStream.Read(Buffer[1], MyFileStream.Size);
Buffer:=IdBase64Encoder1.CodeString(Buffer); //得到编码后的字符串
memo1.Lines.Add(Buffer);
finally
MyFileStream.Free; //eventually
end;
end;
end.