- UID
- 2
注册时间2004-12-1
阅读权限255
最后登录1970-1-1
总坛主
TA的每日心情 | 开心 2024-12-1 11:04 |
---|
签到天数: 12 天 [LV.3]偶尔看看II
|
- unit EncodingUtil;
- interface
- uses
- SysUtils, Classes, Types, EncdDecd;
- function BytesToBase64(const bytes : TByteDynArray) : string;
- function StreamToBase64(AStream: TStream) : string;
- implementation
- function BytesToBase64(const bytes : TByteDynArray) : string;
- var
- memoryStream : TMemoryStream;
- begin
- memoryStream := TMemoryStream.Create;
- memoryStream.WriteBuffer(bytes[0], Length(bytes));
- memoryStream.Seek(0, soFromBeginning);
- Result := StreamToBase64(memoryStream);
- memoryStream.Free;
- end;
- function StreamToBase64(AStream: TStream) : string;
- var
- objSS: TStringStream;
- begin
- objSS := TStringStream.Create('');
- try
- EncodeStream(AStream, objSS); //Delphi7 自带unit EncdDecd的方法
- Result := objSS.DataString;
- finally
- FreeAndNil(objSS);
- end;
- end;
- end.
复制代码
EncdDecd单元:
- //对流的编解码:
- procedure EncodeStream(Input, Output: TStream); // 编码
- procedure DecodeStream(Input, Output: TStream); // 解码
- // 对字符串的编解码:
- function EncodeString(const Input: string): string; // 编码
- function DecodeString(const Input: string): string; // 解码
复制代码
这几个函数在帮助中没有~~ 非公开
|
|