下面的代码,是在网上找到的把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;

解决方案 »

  1.   

    代码没贴全吧,ListEdit.OnKeyPress := ListEditKeyPress;这句在哪儿呢?
      

  2.   

    ListEdit.OnKeyPress := ListEditKeyPress,这句话在哪呢
      

  3.   


    ListEdit.OnKeyPress := ListEditKeyPress(sender)
      

  4.   

    ListEdit.OnKeyPress := ListEditKeyPress
    OnKeyPress和ListEditKeyPress参数要一致才可以。
    不一致,可以copy自动产生的。
      

  5.   


    ListEdit.OnKeyPress := ListEditKeyPress(sender)百度 自定义控件的事件 参考下