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

How to trigger sub componets procedures 1

Status
Not open for further replies.

john230873

Programmer
Oct 3, 2003
89
NZ
I have written 2 classes. 1 called TDayPanel and another called TCalendarPanel, both are classes of TPanel.
The TDayPanel has on onclick event that changes a property and colour of the panel i.e. when clicked if not setected it becomes select and if it is selected it becomes unslected.

The TCalendarPanel has 41 TDayPanel objects

For n := 0 to 41 do
begin
With TPanelDay.Create(Self,GetDateForPanel(n))DO
begin
Left := Panelleft;
Top := PanelTop;
Parent := self;
end;
end;

What I need to do is inside the TCalendarPanel class if any of the TDayPanel objects are clicked then run another procedure. I tried adding the line OnClick := DayPanelClicked; to the above statement but it then overrided the TDayPanel classes onclick procedure. I need both to run.

Any ideas
 
Probably the best way would be to move your code from your TDayPanel.OnClick event into a separate public procedure in your TDayPanel object, and change the TDayPanel.Onclick event to call this procedure.

Then, in your TCalendarPanel object, do whatever you need, and then call the public procedure in the TDayPanel.
 
Makes since but how do I know which TdayPanel to Update and how do I call it when I haven't got a name for the TdayPanel
 
You don't need to know their names.

For n := 0 to 41 do
begin
With TPanelDay.Create(Self,GetDateForPanel(n))DO
begin
Left := Panelleft;
Top := PanelTop;
Parent := self;
OnClick := Form1.UpdateDayPanel
end;
end;


UpdateDayPanel must be written as an TNotifyEvent, which passes the Sender as a parameter. In your UpdateDayPanel, simply refer use this sort of coding:

(Sender as TDayPanel).Tag := 50;

to refer to the particular DayPanel object that was clicked.
 
Thanks you pointed down the right direction. In the end I used.

(Sender as TPanelDay).UpdateDay(Sender);

to call the TPanelDay function.
 
Now thats done when I create a object on the form how do I let the form know there has been a click on the calendar?
 
You could have the same block of code say:

Sender as TPanelDay).UpdateDay(Sender);
Form1.RespondToClick;

or some-such. I don't know at this point if any control has already responded to an OnClick event, or even if the Form1 would ever respond to an OnClick event if a control was clicked instead of the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top