Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

point an event to a function ! 1

Status
Not open for further replies.

masterDicanio

Programmer
May 14, 2005
18
IR
Hi

i want to create an TCombobox in runtime and make onChange event to call a function !

it seems i can not use : comboboxname.onChange := a function , it is wierd (cause onChange is a TNotifyEvent ! then how i can do this ?
 
newComboBox.onChange := functionName


The function must have exactly the same parameters as the event handlers delphi generates for you.
 
kemp , this is the code and the error :

procedure itChanged(Sender: TObject);
begin
showmessage('yes');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
mycbox : TCombobox;
begin
mycbox := tcombobox.Create(self);
mycbox.Parent := form1 ;
mycbox.OnChange := itChanged;
end;

[Error] Unit1.pas(38): Incompatible types: 'method pointer and regular procedure'
 
you need an object method

change your procedure like this :

procedure TForm1.itChanged(Sender: TObject);
begin
showmessage('yes');
end;

add this line in the public or private section of the
TForm1 class (in the interface part of the unit) :

procedure itChanged(Sender: TObject);

then it will work


--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top