NMUUE.pas
上传用户:szzdds
上传日期:2013-09-18
资源大小:293k
文件大小:3k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit NMUUE;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, NMConst;
  5. type
  6.   UUMethods = (uuMime, uuCode);
  7.   TNMUUProcessor = class(TComponent)
  8.   private
  9.     FOnBeginEncode: TNotifyEvent;
  10.     FOnEndEncode: TNotifyEvent;
  11.     FOnBeginDecode: TNotifyEvent;
  12.     FOnEndDecode: TNotifyEvent;
  13.     FInputStream: TStream;
  14.     FOutputStream: TStream;
  15.   protected
  16.     FUUMethod: UUMethods;
  17.   public
  18.     constructor Create(AOwner: TComponent); override;
  19.     procedure Encode;
  20.     procedure Decode;
  21.     property InputStream: TStream read FInputStream write FInputStream;
  22.     property OutputStream: TStream read FOutputStream write FOutputStream;
  23.   published
  24.     property Method: UUMethods read FUUMethod write FUUMethod default uuMime;
  25.     property OnBeginEncode: TNotifyEvent read FOnBeginEncode write FOnBeginEncode;
  26.     property OnEndEncode: TNotifyEvent read FOnEndEncode write FOnEndEncode;
  27.     property OnBeginDecode: TNotifyEvent read FOnBeginDecode write FOnBeginDecode;
  28.     property OnEndDecode: TNotifyEvent read FOnEndDecode write FOnEndDecode;
  29.   end;
  30. implementation
  31. uses
  32.   NM64Encode, NM64Decode, NMUUEncode, NMUUDecode;
  33. {*******************************************************************************
  34. Create NMUUE and set code method to MIME by default
  35. *******************************************************************************}
  36. constructor TNMUUProcessor.Create(AOwner: TComponent);
  37. begin
  38.   inherited;
  39.   FUUMethod := uuMime;
  40. end;
  41. {*******************************************************************************
  42. Encode
  43. *******************************************************************************}
  44. procedure TNMUUProcessor.Encode;
  45. begin
  46.   FInputStream.Position := 0;
  47.   if Assigned(FOnBeginEncode) then
  48.     FOnBeginEncode(self);
  49.   case Method of
  50.     uuMime: B64Encode(FInputStream, FOutputStream);
  51.     uuCode: UUEEncode(FInputStream, FOutputStream);
  52.   end;
  53.   FInputStream.Position := 0;
  54.   FOutputStream.Position := 0;
  55.   if Assigned(FOnEndEncode) then
  56.     FOnEndEncode(self);
  57. end;
  58. {*******************************************************************************************
  59. Decode
  60. ********************************************************************************************}
  61. procedure TNMUUProcessor.Decode;
  62. begin
  63.   FInputStream.Position := 0;
  64.   if Assigned(FOnBeginDecode) then
  65.     FOnBeginDecode(self);
  66.   case Method of
  67.     uuMime: B64Decode(FInputStream, FOutputStream);
  68.     uuCode: UUEDecode(FInputStream, FOutputStream);
  69.   end;
  70.   FInputStream.Position := 0;
  71.   FOutputStream.Position := 0;
  72.   if Assigned(FOnEndDecode) then
  73.     FOnEndDecode(self);
  74. end;
  75. end.