home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Demos / Midas / InternetExpress / InetXCustom / fieldattr.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  4KB  |  128 lines

  1. unit FieldAttr;
  2.  
  3. interface
  4.  
  5. uses Classes, HTTPApp, Db, DbClient, Midas,
  6.   XMLBrokr, WebComp, PagItems, MidItems;
  7.  
  8. type
  9.   TFieldTextAttr = class(TFieldText)
  10.   private
  11.     FRequired: Boolean;
  12.     FDecimals: Integer;
  13.     FMaxValue: string;
  14.     FMinValue: string;
  15.     FFixedDecimals: Integer;
  16.     FCurrencySymbol: string;
  17.   protected
  18.     function ImplGetRowSetFieldAttributes(const FieldVarName: string): string; override;
  19.   public
  20.     constructor Create(AOwner: TComponent); override;
  21.   published
  22.     property Required: Boolean read FRequired write FRequired;
  23.     property Decimals: Integer read FDecimals write FDecimals default -1;
  24.     property FixedDecimals: Integer read FFixedDecimals write FFixedDecimals default -1;
  25.     property MinValue: string read FMinValue write FMinValue;
  26.     property MaxValue: string read FMaxValue write FMaxValue;
  27.     property CurrencySymbol: string read FCurrencySymbol write FCurrencySymbol;
  28.   end;
  29.  
  30.   TTextColumnAttr = class(TTextColumn)
  31.   private
  32.     FRequired: Boolean;
  33.     FDecimals: Integer;
  34.     FMaxValue: string;
  35.     FMinValue: string;
  36.     FFixedDecimals: Integer;
  37.     FCurrencySymbol: string;
  38.   protected
  39.     function ImplGetRowSetFieldAttributes(const FieldVarName: string): string; override;
  40.   public
  41.     constructor Create(AOwner: TComponent); override;
  42.   published
  43.     property Required: Boolean read FRequired write FRequired;
  44.     property Decimals: Integer read FDecimals write FDecimals default -1;
  45.     property FixedDecimals: Integer read FFixedDecimals write FFixedDecimals default -1;
  46.     property MinValue: string read FMinValue write FMinValue;
  47.     property MaxValue: string read FMaxValue write FMaxValue;
  48.     property CurrencySymbol: string read FCurrencySymbol write FCurrencySymbol;
  49.   end;
  50.  
  51.   procedure Register;
  52.  
  53. implementation
  54.  
  55. uses sysutils;
  56.  
  57. function FormatRowSetFieldAttributes(
  58.   const FieldVarName: string;
  59.   Required: Boolean; Decimals, FixedDecimals: Integer;
  60.   const MinValue, MaxValue, CurrencySymbol: string): string;
  61. const
  62.   FalseTrue: array[Boolean] of string = ('false','true');
  63. begin
  64.   Result := '';
  65.   Result := Format('%s%s.required = %s;'#13#10,
  66.     [Result, FieldVarName, FalseTrue[Required]]);
  67.   if Decimals >= 0 then
  68.     Result := Format('%s%s.decimals = %d;'#13#10,
  69.       [Result, FieldVarName, Decimals]);
  70.   if FixedDecimals >= 0 then
  71.     Result := Format('%s%s.fixeddec = %d;'#13#10,
  72.       [Result, FieldVarName, FixedDecimals]);
  73.   if MinValue <> '' then
  74.     Result := Format('%0:s%1:s.minval = %1:s.frdisp("%2:s");'#13#10,
  75.       [Result, FieldVarName, MinValue]);
  76.   if MaxValue <> '' then
  77.     Result := Format('%0:s%1:s.maxval = %1:s.frdisp("%2:s");'#13#10,
  78.       [Result, FieldVarName, MaxValue]);
  79.   if CurrencySymbol <> '' then
  80.     Result := Format('%s%s.currencySymbol = "%s";'#13#10,
  81.       [Result, FieldVarName, CurrencySymbol]);
  82. end;
  83.  
  84. { TFieldTextAttr }
  85.  
  86. constructor TFieldTextAttr.Create(AOwner: TComponent);
  87. begin
  88.   inherited;
  89.   FDecimals := -1;
  90.   FFixedDecimals := -1;
  91. end;
  92.  
  93. function TFieldTextAttr.ImplGetRowSetFieldAttributes(
  94.   const FieldVarName: string): string;
  95. begin
  96.   Result := inherited ImplGetRowSetFieldAttributes(FieldVarName) +
  97.     FormatRowSetFieldAttributes(
  98.      FieldVarName,
  99.      Required, Decimals, FixedDecimals,
  100.      MinValue, MaxValue, CurrencySymbol);
  101. end;
  102.  
  103. procedure Register;
  104. begin
  105.   RegisterWebComponents([TFieldTextAttr, TTextColumnAttr]);
  106. end;
  107.  
  108. { TTextColumnAttr }
  109.  
  110. constructor TTextColumnAttr.Create(AOwner: TComponent);
  111. begin
  112.   inherited;
  113.   FDecimals := -1;
  114.   FFixedDecimals := -1;
  115. end;
  116.  
  117. function TTextColumnAttr.ImplGetRowSetFieldAttributes(
  118.   const FieldVarName: string): string;
  119. begin
  120.   Result := inherited ImplGetRowSetFieldAttributes(FieldVarName) +
  121.     FormatRowSetFieldAttributes(
  122.      FieldVarName,
  123.      Required, Decimals, FixedDecimals,
  124.      MinValue, MaxValue, CurrencySymbol);
  125. end;
  126.  
  127. end.
  128.