unit LinkEdit;interfaceuses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Dialogs;type
TLinkEdit = class(TEdit)
private
FActive: Boolean;
FLink: String;
Procedure SetActiveValue(AValue: Boolean);
Procedure SetLinkValue(ALink: String);
procedure WMKEYdownClick(var Msg: TWMKEYDOWN); message WM_KEYDOWN;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
property Active: Boolean read FActive write SetActiveValue;
property Link: String read FLink write SetLinkValue;
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('XP', [TLinkEdit]);
end;procedure TLinkEdit.SetActiveValue(AValue: Boolean);
begin
if FActive <> AValue then
FActive :=Avalue;
end;procedure TLinkEdit.SetLinkValue(ALink: String);
begin
if FLink <> Alink then
FLink :=Alink;
end;procedure TLinkEdit.WMKEYdownClick(var Msg: TWMKEYDOWN);
var
vEdit:TEdit;
begin
if FActive Then
Begin
if Msg.CharCode = VK_RETURN then
begin
if Flink <> '' then
begin
vEdit:=FindComponent(FLink) as TEdit; //有问题
vEdit.SetFocus;
end;
end;
end;
end;end.这个组件TLinkEdit要实现的是:在按下回车键后把焦点转移到Link指定的Edit,大家看看吧,如果有解决方法请告诉一声,谢谢
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Dialogs;type
TLinkEdit = class(TEdit)
private
FActive: Boolean;
FLink: String;
Procedure SetActiveValue(AValue: Boolean);
Procedure SetLinkValue(ALink: String);
procedure WMKEYdownClick(var Msg: TWMKEYDOWN); message WM_KEYDOWN;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
property Active: Boolean read FActive write SetActiveValue;
property Link: String read FLink write SetLinkValue;
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('XP', [TLinkEdit]);
end;procedure TLinkEdit.SetActiveValue(AValue: Boolean);
begin
if FActive <> AValue then
FActive :=Avalue;
end;procedure TLinkEdit.SetLinkValue(ALink: String);
begin
if FLink <> Alink then
FLink :=Alink;
end;procedure TLinkEdit.WMKEYdownClick(var Msg: TWMKEYDOWN);
var
vEdit:TEdit;
begin
if FActive Then
Begin
if Msg.CharCode = VK_RETURN then
begin
if Flink <> '' then
begin
vEdit:=FindComponent(FLink) as TEdit; //有问题
vEdit.SetFocus;
end;
end;
end;
end;end.这个组件TLinkEdit要实现的是:在按下回车键后把焦点转移到Link指定的Edit,大家看看吧,如果有解决方法请告诉一声,谢谢
var
vEdit:TEdit;
lp: integer;
begin
if FActive Then
Begin
if Msg.CharCode = VK_RETURN then
begin
if Flink <> '' then
begin
vEdit := nil;
for lp := 0 to TWincontrol(Owner).ControlCount - 1 do
begin
if TWincontrol(Owner).Controls[lp] is TEdit then
begin
if UpperCase(TEdit(TWincontrol(Owner).Controls[lp]).Name) =
UpperCase(Flink) then
vEdit := TEdit(TWincontrol(Owner).Controls[lp]);
end;
end;
if Assigned(vEdit) then
vEdit.SetFocus;
end;
end;
end;
end;
vEdit.SetFocus;修改为:
vEdit:=TWincontrol(Owner).FindComponent(FLink) as TEdit; //有问题
if vEdit<>nil then vEdit.SetFocus;
你错误的原因是因为当前的FindComponent是该TEdit的方法,而不是相应的Form的方法.