Solved

TNotifyEvent ?

Posted on 1998-12-20
6
3,472 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
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

770 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