Solved

TNotifyEvent ?

Posted on 1998-12-20
6
3,372 Views
Last Modified: 2010-05-19
i'm beginner of delphi 4, i've bought the delphi books and online help, but i still dont understand how to use TNotifyEvent. can anyone here give me a simple example code.
0
Comment
Question by:qwertyuiopasdfghjkl
  • 3
  • 2
6 Comments
 
LVL 4

Accepted Solution

by:
dwwang earned 30 total points
Comment Utility
To use TNotifyEvent, you just need to declare your procedure/function where other eventhandler of the form is placed:

TMyform=class (TForm)
    .......//those components on the form
    procedure button1click(...);    // the click evetn handler of button1 on your form;
    procedure MyEventHandler(....);      //procedure/function declared here will automatically be a tnotify event

    public
    ...
    private
    .....
end;

Regards,
Wang
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
TNotifyEvent is simply a pointer to a function... Here is how a TNotifyEvent is beign declared...

type
  TSomeEvent = procedure(Sender : TObject);

This is an example of creating your own event...

all the OnCLick() OnMouseMove().. (the ones that are On..) are TNotifyEvents which are executed when that event happens... For example you click on the form and the OnClick() of the form is being executed...

—Viktor
——Ivanov
0
 

Author Comment

by:qwertyuiopasdfghjkl
Comment Utility
viktornet,
then how do i make it automatically fire the event ?



0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Expert Comment

by:dwwang
Comment Utility
Hi, just simply write the event handler as I describe above, then at the property editor you can find the procedure by click the comboBox of one event.

If you want to assign the handler to an invisible component, such as TClientSocket, just write  like:
myClientSock.OnReceiveData:=MyEventHandler(....) //with proper parameter list.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
You can't make it automatically fire the event... You should include that event to be fired somewhere. take this for example... Here i create a TNotifyEvent  property so when the component is painted the code in the OnPaint is executed...

//Component definition and stuff....
type
  TMyComp = class(TGraphicControl)
{...}
private
  FOnPaint : TNotifyEvent;
  procedure Paint; override;
{...}
published
  property OnPaint : TNotifyEvent read FOnPaint write FOnPaint;
{...}
procedure TMyComp.Paint;
begin
  //Maybe some code here...
  if Assigned(FOnPaint) then FOnPaint(self);
  //And probably some more in here...
end;

Now when the component compiled and everything you can drop it on your form and then assign some code in the OnPain() as you do in other controls...

procedure TForm1.MyComp1Paint(Sender : TObject);
begin
  ShowMessage('Our new component is being painted at the moment');
end;

When your component is repainted the message above will be shown...

This is a way to use TNotifyEvent... Usually you make your application take the message like WM_PAINT and then create and event for that,,,

Hope this helps a bit.

Cheers,
Viktor
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
oh, yeah... as Wang mentioned you can do stuff like this...

type
  TForm1 = class(TForm)
{whatever}
public
  procedure MyOnClickEvent(Sender : TObject);
{stuff}
end;

procedure TForm1.MyOnClickEvent(Sender : TObject);
begin
  ShowMessage('There you go. We just experienced the OnClick() of ' + TObject(Sender).Name);
end;

Now anywhere in your program you can do stuff like this...

NameOfMyControl.OnClick := MyOnClickEvent;
e.g.
Form1.OnClick := MyOnClickEvent;

Hope this helps...

-Viktor
--Ivanov
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now