Solved

TNotifyEvent ?

Posted on 1998-12-20
6
3,590 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 30 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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