可别再说我灌水啦:
Indy已经是D6的集成控件组了,所以我用了Indy的TIndyBase64Encoder,真的好简单啊。
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.