这些代码出错在哪儿了

cd20102010 2011-01-26 04:27:43
下面的代码,是在网上找到的把Edit嵌入到Listbox中的代码。可是高度时,总是卡在了 ListEdit.OnKeyPress := ListEditKeyPress;这句,说是参数不匹配,请问怎么修改才行啊?

type
TForm1 = class(TForm)
...
private
ListEdit : TEdit;
procedure ListEditKeyPress(Sender: TObject; var Key: Char) ;
end;

...

//create the TEdit and make ListBox its parent
procedure TForm1.FormCreate(Sender: TObject) ;
begin
ListEdit := TEdit.Create(self) ;
ListEdit.Visible := false;
ListEdit.Ctl3D := false;
ListEdit.BorderStyle := bsNone;
ListEdit.Parent := ListBox1;
ListEdit.Width := ListBox1.ClientWidth;
[color=#FF0000]color]end;

//ListView Item selected - position the Edit
procedure TForm1.ListBox1Click(Sender: TObject) ;
var
ii : integer;
lRect: TRect;
begin
ii := ListBox1.ItemIndex;
if ii = -1 then exit;

lRect := ListBox1.ItemRect(ii) ;
ListEdit.Top := lRect.Top + 1;
ListEdit.Left := lRect.Left + 1;
ListEdit.Height := (lRect.Bottom - lRect.Top) + 1;

ListEdit.Text := ListBox1.Items.Strings[ii];
ListBox1.Selected[ii] := False;

ListEdit.Visible := True;
ListEdit.SelectAll;
ListEdit.SetFocus;
end;

//apply editing when enter key is pressed
procedure TForm1.ListEditKeyPress(Sender: TObject; var Key: Char) ;
var
ii: Integer;
begin
if Key = #13 then
begin
ii := ListBox1.ItemIndex;
ListBox1.Items.Delete(ii) ;
ListBox1.Items.Insert(ii, ListEdit.Text) ;
ListEdit.Visible := False;
Key := #0;
end;
end;

//hide Edit when ListBox looses the focus
procedure TForm1.ListBox1Exit(Sender: TObject) ;
begin
ListEdit.Visible := false;
end;
...全文
98 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pronetsky 2011-01-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 smallhand 的回复:]
ListEdit.OnKeyPress := ListEditKeyPress
OnKeyPress和ListEditKeyPress参数要一致才可以。
不一致,可以copy自动产生的。
[/Quote]

ListEdit.OnKeyPress := ListEditKeyPress(sender)

百度 自定义控件的事件 参考下
火龙岛主 2011-01-26
  • 打赏
  • 举报
回复
ListEdit.OnKeyPress := ListEditKeyPress
OnKeyPress和ListEditKeyPress参数要一致才可以。
不一致,可以copy自动产生的。
vivai2010 2011-01-26
  • 打赏
  • 举报
回复

ListEdit.OnKeyPress := ListEditKeyPress(sender)
bdmh 2011-01-26
  • 打赏
  • 举报
回复
ListEdit.OnKeyPress := ListEditKeyPress,这句话在哪呢
JPEXE 2011-01-26
  • 打赏
  • 举报
回复
代码没贴全吧,ListEdit.OnKeyPress := ListEditKeyPress;这句在哪儿呢?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧