我想在一个CheckBox控件的click事件中调用同一窗体的Combox控件的KeyPress事件,写了如下代码:
procedure Tform1.CheckBox1Click(Sender: TObject);
begin
comb2.OnKeyPress(f_del,#13);
end;
结果提示:Types of actual and formal var parameters must be identical
应该怎么改才行呢?
procedure Tform1.CheckBox1Click(Sender: TObject);
begin
comb2.OnKeyPress(f_del,#13);
end;
结果提示:Types of actual and formal var parameters must be identical
应该怎么改才行呢?
begin
comb2.OnKeyPress(sender);
end;
需要变量,你的是常量
不能直接这样调用的,如果真的想调用OnKeyPress事件可以使用消息触发,不过相当麻烦。
其实可以将你的OnKeyPress事件的处理函数再封装,
既把 if key=#13 then
begin end;
里的东东封装成过程。
combobox1.OnChange(self );
combobox1.OnChange(combobox1.NewInstance );
上面3种方法都可以
TForm1.ComboBox1Press(Sender: TObject; var Key: Char);
begin
if key = #13 then
Procedure_xxx;
end;
那么,你就可以在CheckBox1的单击事件中这样调用:
procedure Tform1.CheckBox1Click(Sender: TObject);
begin
Procedure_xxx;
end;
合理组织程序代码对复用和扩展都有好处。