Dr.Bob's TUUCode Component

Last updated: 1997/03/29
John Kaster, Loren Scott, Ted Blue and yours truly Bob Swart (aka Dr.Bob) are working on a book entitled "Delphi Internet Solutions", which will contain some interesting topics about Delphi and the internet and intranet. Little pieces of information and parts of chapters will be made available from now on to get your attention ;-)

New is the 16/32-bits version 3.0 of my TUUCode component, capable of uuencode/decode, xxencode/decode, base64-encode/decode and plain filecopy.
You can download version 3.0 (gamma) from my ftp site at ftp://ftp.iaehv.nl/pub/users/ajansen:

Note that you get the registration unit and an example program with sources files as well, but the component UUCODE.PAS source file will only be available in .DCU format (and .OBJ for BCB); full sources are not available at this time but will be present in the book of course!


Interface

  unit UUCode;
  { TUUCode version 3.0 - 1997/03/29 }
  interface
  uses
  {$IFDEF WIN32}
    Windows,
  {$ELSE}
    WinTypes, WinProcs,
  {$ENDIF}
    SysUtils, Messages, Classes, Graphics, Controls, Forms;

  {$IFNDEF WIN32}
  type
    ShortString = String;
  {$ENDIF}

  type
    EUUCode = class(Exception);

    TAlgorithm = (filecopy,
                  uuencode, uudecode,
                  xxencode, xxdecode,
                  base64encode, base64decode);
    TUnixCRLF = (CRLF, LF);

    TProgressEvent = procedure(Percent: Word) of Object;

    TUUCode = class(TComponent)
    public
    { Public class declarations (override) }
      constructor Create(AOwner: TComponent); override;

    private
    { Private field declarations }
      FAbout: ShortString;
      FActive: Boolean;
      FAlgorithm: TAlgorithm;
      FFileMode: Word;
      FHeaders: Boolean;
      FInputFileName: TFileName;
      FOutputFileName: TFileName;
      FOnProgress: TProgressEvent;
      FUnixCRLF: TUnixCRLF;
    { Dummy method to get read-only About property }
      procedure Dummy(Ignore: ShortString);

    protected
    { Protected Activate method }
      procedure Activate(GoActive: Boolean);

    public
    { Public UUCode interface declaration }
      procedure UUCode;

    published
    { Published design declarations }
      property About: ShortString read FAbout write Dummy;
      property Active: Boolean read FActive write Activate;
      property Algorithm: TAlgorithm read FAlgorithm write FAlgorithm;
      property FileMode: Word read FFileMode write FFileMode;
      property Headers: Boolean read FHeaders write FHeaders;
      property InputFile: TFileName read FInputFileName write FInputFileName;
      property OutputFile: TFileName read FOutputFileName write FOutputFileName;
      property UnixCRLF: TUnixCRLF read FUnixCRLF write FUnixCRLF;

    published
    { Published Event property }
      property OnProgress: TProgressEvent read FOnProgress write FOnProgress;
    end {TUUCode};

  implementation
  end.

Properties

About
This property contains the copyright and version information.

Active
This property can be used to call the UUCode method at design time.

Algorithm
This property contains the algorithm to be executed by UUCode. The following algorithms are implemented:

FileMode
This property contains the filemode (typically 0644 or 0755). Note that filemode has to be specified in decimal format (and not octal).

Headers
This property can be used to specify the generation/parsing of begin/end-headers in encoded files. Default is True.

InputFile
This property holds the name of the input file.

OutputFile
This property holds the name of the output file. Note that when decoding a file, the output file may already be specified in the encoded file (when using headers).

UnixCRLF
This property is used to specify Unix-style LF usage or DOS/Windows-style CR/LF pairs. Default is CRLF.


Methods

Create
The public constructor Create is used to create the component TUUCode.

Activate
The protected method Activate is used to call the public method UUCode. This method is needed to ensure that we can "call" UUCode at design-time (when we give the property Active the value True).

UUCode
The public method UUCode is where the work is done based on the values of the properties.


Events

OnProgress
During the UUCode process, we can let the component call a callback routine that contains the percentage of the work completed so far. We can use this Percent argument in combination with a TGauge ot TProgressBar component to show the progress of the conversion process.


Usage

The code you can download contains a small example program. I'm already working on some more detailed example programs (and new features in the TUUCode component - based on the feedback I receive, of course).

If you have any problems with this component, I'd love to hear about it by e-mail. You are free to use it in any of your programs in any means you want, as long as you don't hold me responsible for any damage that may result from using TUUCode.


Dr.Bob's Delphi Clinic