自定义控件加几个实用属性!!疑难问题????请大家多帮忙,分数不多,如嫌不够以后再加!!只有这么多了!!(30分)

  • 主题发起人 主题发起人 jack.shi
  • 开始时间 开始时间
J

jack.shi

Unregistered / Unconfirmed
GUEST, unregistred user!
问题一:
procedure TCustomMyEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);

if ksReturn in Keys then
if Key = Chr(Vk_Return) then
begin
Key := Chr(0);
(Owner as TControl).Perform(wm_NextDlgCtl, 0, 0);
end;
if ksEscape in Keys then
begin
if Key = Chr(Vk_Escape) then
begin
Key := Chr(0);
(Owner as TControl).Perform(wm_NextDlgCtl, 1, 0);
end;
end;
end;

请问以上程序有什么问题吗?
加入以上语句后控件就可以多行编辑了,请问如何实现单行编辑!!
该控件继承自TCustomEdit。


问题二:
procedure TMyButton.SetDefault(const Value: Boolean);
var
Form: TCustomForm;
begin
FDefault := Value;
if HandleAllocated then
begin
Form := GetParentForm(Self);
if Form <> nil then
Form.Perform(CM_FOCUSCHANGED, 0, Longint(Form.ActiveControl));
end;
end;
请问以上程序有什么问题吗?
但我自定义的按钮控件为何不支持Default属性,Default属性已经加上了,但不管用!!
该控件继承自TCustomControl。

请大家多帮忙,分数不多,如嫌不够以后再加!!
 
没人看!!不会吧!!
 
还是没人答!!只得自己提前!!
 
问题一:
ksEscape与Keys的定义是什么?
试了一下,
去掉if ksEscape in Keys then就不会产生多行编辑的问题。
问题二:
看看TButton的源码,搜索一下FDefault。

问题一的测试源码:
//只是测试
unit CustomMyEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;

type
TCustomMyEdit = class(TCustomEdit)
private
{ Private declarations }
protected
procedure KeyPress(var Key: Char);override;
public
constructor Create(AOwner: TComponent);override;
published
property Anchors;
property AutoSelect;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property BiDiMode;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property MaxLength;
property OEMConvert;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('dwh', [TCustomMyEdit]);
end;

constructor TCustomMyEdit.Create(AOwner: TComponent);
begin
inherited;
end;

procedure TCustomMyEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);

// if ksReturn in Keys then
if Key = Chr(Vk_Return) then
begin
Key := Chr(0);
(Owner as TControl).Perform(wm_NextDlgCtl, 0, 0);
end;
// if ksEscape in Keys then
begin
if Key = Chr(Vk_Escape) then
begin
Key := Chr(0);
(Owner as TControl).Perform(wm_NextDlgCtl, 1, 0);
end;
end;
end;

end.
 
问题已经解决,找到原因了!!谢谢!!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
477
import
I
后退
顶部