home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d456 / VOLGAPAK.ZIP / Source / VolHintProp.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-20  |  1.7 KB  |  83 lines

  1. unit VolHintProp;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   {$IFDEF VER140} DesignIntf, DesignEditors, {$ELSE} DsgnIntf, {$ENDIF}
  8.   StdCtrls, Buttons, TypInfo;
  9.  
  10. type
  11.  
  12.   TfrmVHintEdit = class(TForm)
  13.     Memo: TMemo;
  14.     btnSave: TBitBtn;
  15.     btnCancel: TBitBtn;
  16.     btnClear: TBitBtn;
  17.     procedure btnClearClick(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. { TVHintProperty }
  25.  
  26.   TVHintProperty = class(TStringProperty)
  27.   public
  28.     function GetAttributes: TPropertyAttributes; override;
  29.     function GetEditLimit: Integer; override;
  30.     procedure Edit; override;
  31.   end;
  32.  
  33.   procedure Register;
  34.  
  35. implementation
  36.  
  37. {$R *.DFM}
  38. const BaseClass: TClass = TComponent;
  39.  
  40. procedure Register;
  41. begin
  42.   RegisterPropertyEditor(TypeInfo(string), BaseClass, 'Hint', TVHintProperty);
  43. end;
  44.  
  45. function TVHintProperty.GetAttributes: TPropertyAttributes;
  46. begin
  47.   Result := inherited GetAttributes + [paDialog];
  48. end;
  49.  
  50. function TVHintProperty.GetEditLimit: Integer;
  51. begin
  52.   if GetPropType^.Kind = tkString then
  53.     Result := GetTypeData(GetPropType)^.MaxLength
  54.   else Result := 1024;
  55. end;
  56.  
  57. procedure TVHintProperty.Edit;
  58. var
  59.   Comp: TPersistent;
  60. begin
  61.   with TfrmVHintEdit.Create(Application) do
  62.   try
  63.     Comp := GetComponent(0);
  64.     if Comp is TComponent then
  65.       Caption := TComponent(Comp).Name + '.' + GetName
  66.     else Caption := GetName;
  67.     Memo.Lines.Text := GetStrValue;
  68.     Memo.MaxLength := GetEditLimit;
  69.     if ShowModal = mrOk then begin
  70.       SetStrValue(Memo.Lines.Text);
  71.     end;
  72.   finally
  73.     Free;
  74.   end;
  75. end;
  76.  
  77. procedure TfrmVHintEdit.btnClearClick(Sender: TObject);
  78. begin
  79.   Memo.Lines.Clear;
  80. end;
  81.  
  82. end.
  83.