TMyEdit = class(TCustomControl)
private
procedure CreateParams(var Params: TCreateParams); override;
procedure SetSelText(const Value: string);
procedure CMEnter(var Message: TCMGotFocus); message CM_ENTER;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
protected
procedure Change; dynamic;
published
property TabStop default True;
property Text;
public
constructor Create(AOwner: TComponent); override;
procedure SetSelTextBuf(Buffer: PChar);
end;
constructor TMyEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Color := clWhite;
Width := 121;
Height := 25;
TabStop := True;
ParentColor := False;
end;
procedure TMyEdit.SetSelTextBuf(Buffer: PChar);
begin
SendMessage(Handle, EM_REPLACESEL, 0, LongInt(Buffer));
end;
procedure TMyEdit.SetSelText(const Value: String);
begin
SendMessage(Handle, EM_REPLACESEL, 0, Longint(PChar(Value)));
end;
procedure TMyEdit.CMEnter(var Message: TCMGotFocus);
begin
inherited;
end;
procedure TMyEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
CreateSubClass(Params, 'MyEDIT');
with Params do
begin
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
end;
end;
procedure TMyEdit.CMFontChanged(var Message: TMessage);
begin
end;
procedure TMyEdit.CNCommand(var Message: TWMCommand);
begin
if (Message.NotifyCode = EN_CHANGE) then Change;
end;
procedure TMyEdit.CMTextChanged(var Message: TMessage);
begin
inherited;
if not HandleAllocated or (GetWindowLong(Handle, GWL_STYLE) and
ES_MULTILINE <> 0) then Change;
end;
procedure TMyEdit.Change;
begin
inherited Changed;
end;