>>单元文件
{StrEditor.pas}
unit StrEditor;
interface
uses Windows,Classes, Controls, StdCtrls,Buttons, TypInfo,Forms,ExtCtrls,{$IFDEF VER140}DesignIntf, VCLEditors
{$else
}DsgnIntf{$ENDIF};
type
TStrEditDlg = class(TForm)
Memo: TMemo;
BtnOK: TBitBtn;
BtnCancel: TBitBtn;
Bevel1: TBevel;
BtnAbout: TBitBtn;
Label1: TLabel;
procedure BtnAboutClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure CreateParams(var Param:TCreateParams);override;
end;
type
TCaptionEditor = class(TCaptionProperty)
public
function GetAttributes: TPropertyAttributes;
override;
procedure Edit;
override;
end;
procedure Register;
implementation
{$R *.DFM}
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(TCaption), TObject, 'Caption', TCaptionEditor);
RegisterPropertyEditor(TypeInfo(TCaption), TObject, 'Text', TCaptionEditor);
RegisterPropertyEditor(TypeInfo(string), TObject, 'Hint', TCaptionEditor);
end;
{ Register }
{ THintProperty }
procedure TCaptionEditor.Edit;
var
Comp : TPersistent;
begin
with TStrEditDlg.Create(Application)do
try
Comp := GetComponent(0);
if Comp is TComponent then
Caption := TComponent(Comp).Name + '.' + GetName
else
Caption := GetName;
Memo.Text :=GetStrValue;
Memo.SelectAll;
if ShowModal = mrOk then
SetStrValue(Memo.Text);
finally
Free;
end;
end;
{ TCaptionEditor.Edit }
function TCaptionEditor.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog];
end;
{ TCaptionEditor.GetAttributes }
procedure TStrEditDlg.BtnAboutClick(Sender: TObject);
begin
MessageBox(Handle,'Copyright (C) Kingron 2002','Info',MB_OK+MB_ICONINFORMATION);
end;
{ TStrEditDlg.BtnAboutClick }
procedure TStrEditDlg.CreateParams(var Param: TCreateParams);
begin
inherited;
Param.WndParent :=GetActiveWindow;
end;
end.
>>窗体文件
{StrEditor.dfm}
object StrEditDlg: TStrEditDlg
Left = 283
Top = 106
BorderStyle = bsDialog
Caption = 'String Editor'
ClientHeight = 221
ClientWidth = 347
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
DesignSize = (
347
221)
PixelsPerInch = 96
TextHeight = 13
object Bevel1: TBevel
Left = 8
Top = 11
Width = 329
Height = 161
Anchors = [akLeft, akTop, akRight, akBottom]
Shape = bsFrame
end
object Label1: TLabel
Left = 17
Top = 20
Width = 139
Height = 13
Caption = 'Press Ctrl+Enter to break line:'
end
object Memo: TMemo
Left = 16
Top = 40
Width = 313
Height = 121
Anchors = [akLeft, akTop, akRight, akBottom]
HideSelection = False
ScrollBars = ssVertical
TabOrder = 0
WantReturns = False
end
object BtnOK: TBitBtn
Left = 176
Top = 188
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&OK'
TabOrder = 1
Kind = bkOK
end
object BtnCancel: TBitBtn
Left = 264
Top = 188
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&Cancel'
TabOrder = 2
Kind = bkCancel
end
object BtnAbout: TBitBtn
Left = 8
Top = 188
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&About'
TabOrder = 3
OnClick = BtnAboutClick
Kind = bkHelp
end
end