Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TNotifyEvent ?

Posted on 1998-12-20
6
Medium Priority
?
3,820 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
[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 4

Accepted Solution

by:
dwwang earned 120 total points
ID: 1352325
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
ID: 1352326
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
ID: 1352327
viktornet,
then how do i make it automatically fire the event ?



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:dwwang
ID: 1352328
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
ID: 1352329
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
ID: 1352330
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

670 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