home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DELPHI / LEADZR / LEADZERO.PAS < prev    next >
Pascal/Delphi Source File  |  1995-04-27  |  2KB  |  76 lines

  1. unit Leadzero;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TZeroFill = class(TComponent)
  11.   private
  12.     { Private declarations }
  13.     function GetStrVal : String;
  14.  
  15.   protected
  16.     { Protected declarations }
  17.  
  18.     FInputVal   : LongInt;
  19.     FStrVal     : String;
  20.     FWidth      : Integer;
  21.     FAlign      : String;
  22.   public
  23.     { Public declarations }
  24.     function FillZeroes(rstSize, inVal : LongInt; aAlign : String ) : String;
  25.  
  26.   published
  27.     { Published declarations }
  28.     {Integer value}
  29.     property InputVal : LongInt read FInputVal write FInputVal;
  30.     {What's returned}
  31.     property StrVal   : String  read GetStrVal;
  32.     {The width of the string to return}
  33.     property Width    : Integer read FWidth    write FWidth;
  34.     {Justification - must be 'Right' or 'Left'}
  35.     property Align    : String  read FAlign    write FAlign;
  36.  
  37.   end;
  38.  
  39. procedure Register;
  40.  
  41. implementation
  42.  
  43. function TZeroFill.GetStrVal : String;
  44. var
  45.    I,
  46.    endI : Integer;
  47. begin
  48.  
  49.    endI := Width - Length(IntToStr(InputVal));
  50.  
  51.    Result := IntToStr(InputVal);
  52.    for I := 1 to endI do
  53.        if Align = 'Right' then
  54.           Result := '0' + Result
  55.        else
  56.           Result := Result + '0';
  57. end;
  58.  
  59. function TZeroFill.FillZeroes(rstSize, inVal : LongInt; aAlign : String ) : String;
  60. begin
  61.  
  62.    InputVal := inVal;
  63.    Align    := aAlign;
  64.    Width    := rstSize;
  65.  
  66.    Result := StrVal;
  67.  
  68. end;
  69.  
  70. procedure Register;
  71. begin
  72.   RegisterComponents('String', [TZeroFill]);
  73. end;
  74.  
  75. end.
  76.