?
Solved

OnDragDrop event

Posted on 1998-12-29
6
Medium Priority
?
249 Views
Last Modified: 2010-04-04
Hello,
  I'm writing a TCalendar component based on TPanel. Each day is an object witch ancestor is TCustomPanel.
In Order to perform a period selection i use each days's Drag/Drop events with something like this :
If source is TCustomPanel then
begin
  // code for painting the selected period
end;

All of this works nice.
Here is my problem :
 In case of the source is not TCustomPanel I want to raise an event from the TCalendar, with those parameters :
  Sender : Tobject ; TheDate:TDate

So :
  1) How do i create my own event on the TCalendar
  2) How does each TJour could raise this event with the parameters

PS : Each day "knows" witch date is represents

Thanks in advance
0
Comment
Question by:helpme020897
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 800 total points
ID: 1353584
Hi...

try this:

type
  TDayDragEvent = procedure(Sender: TObject; theDate: TDate) of object;
  TCalendar = class(TCustomPanel)
    ...
  private
    ...
    FOnDayDrag: TDayDragEvent;
    procedure SetOnDayDrag(proc: TDayDragEvent);
    ...
  public
    ...
  published
    ...
    property OnDayDrag: TDayDragEvent read FDayDrag write SetOnDayDrag;
    ...
  end;

procedure TCalendar.SetOnDayDrag(proc: TDayDragEvent);
begin
  if @FOnDayDrag<>@proc then begin
    FOnDayDrag:=proc;
    ...
  end;
end;

To fire this event you should write something like this:

  if Assigned(FOnDayDrag) then
    FOnDayDrag(self,FMyDate);

Regards, Madshi.

P.S: Any more questions? Please ask...
0
 

Author Comment

by:helpme020897
ID: 1353585
I m testing Madshi's help ....

0
 

Author Comment

by:helpme020897
ID: 1353586
WONDERFULL !!   :-)   :-)  :-)
It works very fine ! except just one very little mistake :

Property OnDayDrag:TDragEvent read fOnDayDrag write SetOnDayDrag
                                    ^^
I write this because of if someone else would like starting with event creatin and read this question later. :-)

Madshi :could you explain step by step exactly what you wrote ? This, because i wrote all, but did not understand everything.

Greatests thanks.

HelpMe
                                     
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:Madshi
ID: 1353587
It's quite easy.
First of all you have to define an event procedure/function type. You did that in your question already.
I only wrote it in Delphi syntax:
type
  TDayDragEvent = procedure(Sender: TObject; theDate: TDate) of object;

You must add this "of object" because the event is part of the object. The event handler will look like
procedure TCalender1.DayDrag(Sender: TObject; theDate: TDate);

The "of object" has two effects: There must be an object in front of the procedure ("TCalender1.") and there will be a hidden "self" parameter that you can use inside the procedure.

Now when the user of your component now clicks into the object inspector to write a handler procedure for your OnDayDrag event, Delphi will automatically write an empty new procedure with the right parameters like you know it from OnCreate.
Now your component has to save the address of this new event handler procedure, since you want to jump to it later, when the event is about to be fired.
So you have to create a private variable. I called it "FOnDayDrag".
Ok, now you must add a new property, so that the object inspector displays your event.
This is done by the line
    property OnDayDrag: TDayDragEvent read FDayDrag write SetOnDayDrag;
You could have written
    property OnDayDrag: TDayDragEvent read FDayDrag write FDayDrag;
too. Then you would not need the SetOnDayDrag procedure. But then you can't execute any code if a handler is added. If that is ok for you, then you should delete the SetOnDayDrag function and change the property line.
Otherwise you'll have to write the simple SetOnDayDrag procedure. In this procedure I first checked if the address of the function changed ("@func1<>@func2"). If not, nothing needs to be done. If yes, we must save the new handler procedure address in our variable FOnDayDrag, then perhaps execute some additional code.
Finally, if you want the event to be fired, you just need to look if somebody wants this event (that means if FOnDayDrag is not nil). If it is not assigned (you can write "if Assigned(FOnDayDrag) then" or "if @FOnDayDrag<>nil then") then do nothing. Otherwise just jump to the handler procedure by writing "FOnDayDrag(self,FMyDate)".

Regards, Madshi.

Hmmm. What was wrong with my sources? I don't see any mistakes...
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1353588
Madshi: After your comment regarding using @ when assigning proc pointers you go and do this :-) :-) :-)

You don't need them when comparing event handlers.

Cheers,

Raymond.

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1353589
Hi Raymond!

You NEED it here...   :-)
If I write "if FOnDayDrag<>..." Delphi will say "parameter missing" because Delphi thinks I want to execute FOnDayDrag.

Regards, Madshi.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question