home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d456 / DCSLIB25.ZIP / DCCapProp.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-20  |  3KB  |  152 lines

  1. {
  2.  BUSINESS CONSULTING
  3.  s a i n t - p e t e r s b u r g
  4.  
  5.          Components Library for Borland Delphi 4.x, 5.x
  6.          Copyright (c) 1998-2000 Alex'EM
  7.  
  8. }
  9. unit DCCapProp;
  10.  
  11. interface
  12. {$I DCConst.inc}
  13.  
  14. uses
  15.   {$IFDEF DELPHI_V6}
  16.     DesignIntf, DesignEditors, DesignWindows,
  17.     VCLEditors,
  18.   {$ELSE}
  19.     Dsgnintf, DsgnWnds,
  20.   {$ENDIF}  
  21.   Dialogs;
  22.  
  23. type
  24.  
  25. { THintProperty }
  26.   TCapProperty = class(TCaptionProperty)
  27.   public
  28.     function GetAttributes: TPropertyAttributes; override;
  29.     function GetEditLimit: Integer; override;
  30.     procedure Edit; override;
  31.   end;
  32.  
  33. {TCaptionProperty}
  34.   TCapEditor = class(TDefaultEditor)
  35.   protected
  36.  {$IFDEF DELPHI_V6}
  37.     procedure EditProperty(const Prop: IProperty;
  38.       var Continue: Boolean); override;
  39.  {$ELSE}
  40.     procedure EditProperty(PropertyEditor: TPropertyEditor;
  41.       var Continue, FreeEditor: Boolean); override;
  42.  {$ENDIF}
  43.   public
  44.     procedure ExecuteVerb(Index: Integer); override;
  45.     function GetVerb(Index: Integer): string; override;
  46.     function GetVerbCount: Integer; override;
  47.   end;
  48.  
  49. implementation
  50.  
  51. uses SysUtils, Classes, TypInfo, Forms, Controls,
  52.      DCCapEdit;
  53.  
  54. procedure EditCapProperty(PropertyEditor: TPropertyEditor);
  55. var
  56.   PropName, Temp: string;
  57.   Comp: TPersistent;
  58. begin
  59.   PropName := PropertyEditor.GetName;
  60.   with TStringEditDlg.Create(Application) do
  61.   begin
  62.     try
  63.       with PropertyEditor do
  64.       begin
  65.         Comp := GetComponent(0);
  66.         if Comp is TComponent then
  67.           Caption := TComponent(Comp).Name + '.' + GetName
  68.         else Caption := GetName;
  69.         Temp := Value;
  70.         Memo.Text := Temp;
  71.         Memo.MaxLength := GetEditLimit;
  72.         UpdateStatus(nil);
  73.         if ShowModal = mrOk then begin
  74.           Temp := Memo.Text;
  75.           while (Length(Temp) > 0) and (Temp[Length(Temp)] < ' ') do
  76.             System.Delete(Temp, Length(Temp), 1);
  77.           Value := Temp;
  78.         end;
  79.       end;
  80.     finally
  81.       Free;
  82.     end;
  83.   end;
  84. end;
  85.  
  86.  
  87. function TCapProperty.GetAttributes: TPropertyAttributes;
  88. begin
  89.   Result := inherited GetAttributes + [paDialog];
  90. end;
  91.  
  92. function TCapProperty.GetEditLimit: Integer;
  93. begin
  94.   if GetPropType^.Kind = tkString then
  95.     Result := GetTypeData(GetPropType)^.MaxLength
  96.   else Result := 1024;
  97. end;
  98.  
  99. procedure TCapProperty.Edit;
  100. begin
  101.   EditCapProperty(Self);
  102. end;
  103.  
  104. { TCapEditor }
  105.  
  106.  
  107. {$IFDEF DELPHI_V6}
  108.   procedure TCapEditor.EditProperty(const Prop: IProperty;
  109.     var Continue: Boolean);
  110.   var
  111.     PropName: string;
  112.   begin
  113.     PropName := Prop.GetName;
  114.     if (CompareText(PropName, 'CAPTION') = 0) then
  115.     begin
  116.       Prop.Edit;
  117.       Continue := False;
  118.     end;
  119.   end;
  120. {$ELSE}
  121.   procedure TCapEditor.EditProperty(PropertyEditor: TPropertyEditor;
  122.     var Continue, FreeEditor: Boolean);
  123.   var
  124.     PropName: string;
  125.   begin
  126.     PropName := PropertyEditor.GetName;
  127.     if (CompareText(PropName, 'CAPTION') = 0) then
  128.     begin
  129.       EditCapProperty(PropertyEditor);
  130.       Continue := False;
  131.     end;
  132.   end;
  133. {$ENDIF}
  134.  
  135. procedure TCapEditor.ExecuteVerb(Index: Integer);
  136. begin
  137.   if Index = 0 then Edit;
  138. end;
  139.  
  140. function TCapEditor.GetVerb(Index: Integer): string;
  141. begin
  142.   if Index = 0 then
  143.     Result := '&Caption Editor ...'
  144.   else Result := '';
  145. end;
  146.  
  147. function TCapEditor.GetVerbCount: Integer;
  148. begin
  149.   Result := 1;
  150. end;
  151.  
  152. end.