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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function Pointer

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi there,
(by the way anyone knows where to download latest d7 service pack?: need to kill delphi32 about 3 times per day when closing IDE...)

Using Delphi 7... Here's my problem:
I have one main Unit (Grid) which uses a SubUnit (Combo).
After a combo selection is done in the SubUnit, I need to send back the selected value to the main Unit.

Thats is, I think the best way to achieve this is to use a function pointer (or in this case a procedure pointer). Something like:

/////////////////////////////////////////////////////////
procedure MainUnit.OnComboOpen(Sender: TObject);
begin
SubUnit.AfterComboSelect := Addr(OnComboSelect);
end;

procedure MainUnit.OnComboSelect(Sender: TObject);
begin
Cells[Col, Row] := (Sender as TComboBox).Text
end;
//////////////////////////////////////////////////////////
procedure SubUnit.OnClick(Sender: TObject);
begin
AfterComboSelect(Self);
end;

procedure SubUnit.OnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_RETURN then AfterComboSelect(Self);
end;

procedure SubUnit.AfterComboSelect(Sender: TObject);
begin
Hide;
// HOW TO SEND BACK RESULT TO MAIN UNIT ???
// (call to MainUnit.OnComboSelect(Self);)
end;

//////////////////////////////////////////////////////////

Anyone can help?

Thanks in advance,

Rej Cloutier
 
Hello there,

I have found my way!

Here's the code I've writtten to do what I've explained.
Hope the code will help somebody else!

See ya!

//////////////////////////////////////////////////////////
MainUnit (type section)
private eColCombo: TNotifyEvent;
public procedure ColComboSelect(Sender: TObject);
published property OnColComboSelect: TNotifyEvent
read eColCombo write eColCombo;

procedure MainUnit.ComboOpen;
begin
// event to call after combo selection
SubUnit.OnComboSelect := ColComboSelect;
SubUnit.ComboOpen;
end;
//////////////////////////////////////////////////////////
SubUnit
private eComboSelect: TNotifyEvent;
published property OnComboSelect: TNotifyEvent
read eComboSelect write eComboSelect;

procedure SubUnit.OnClick(Sender: TObject);
begin
// event from the MainUnit
OnComboSelect(Self);
end;
//////////////////////////////////////////////////////////
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top