Board index » delphi » how to use events of non-visual components

how to use events of non-visual components

I can write event routines for visual components like buttons easily (using
the objectinspector). But how can i write them for non visual components
like TStringlist.OnChange ?

Thanks
Michael

 

Re:how to use events of non-visual components


On Tue, 29 Feb 2000 23:12:05 +0100, "Michael Ahlers" <M.Ahl...@gmx.de>
wrote:

Quote
> But how can i write them for non visual components
> like TStringlist.OnChange ?

Simple, like this:

  StringList.OnChange := MyChangeHandler;

Where the event-handler method (MyChangeHandler) is "type-compatible"
with the event type. Type-compatible means that the event-handler must
have the same interface (procedure or function, same parameters) as
the event type, and must be a method of a class if the "of object"
keywords are included in the event type declaration.

TStringList.OnChange is of type TNotifyEvent, which is declared:

type
  TNotifyEvent = procedure (Sender: TObject) of object;

Which means MyChangeHandler could look like this:

procedure TForm1.MyChangeHandler(Sender: TObject);
begin
  { Do something here }
end;
--
Rick Rogers (TeamB)
www.fenestra.com and www.componentfactory.com

Re:how to use events of non-visual components


I think you'd it just like for any visible component:

mylist.OnChange := MyChange;

procedure TForm1.MyChange(Sender : TObject);
begin

end;

Paul / ColumbuSoft
www.columbusoft.com

Quote
Michael Ahlers <M.Ahl...@gmx.de> wrote in message

news:89hfvu$ka31@bornews.borland.com...
Quote
> I can write event routines for visual components like buttons easily
(using
> the objectinspector). But how can i write them for non visual components
> like TStringlist.OnChange ?

> Thanks
> Michael

Re:how to use events of non-visual components


Quote
>But how can i write them for non visual components
> like TStringlist.OnChange ?

Simply redefine the OnChange event to one of your procedure
ex:
private
  procedure ListChanged(Sender: TObject);
...
...

procedure TForm1.ListChanged(Sender: TObject);
begin
  ShowMessage('My List has changed !');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ...
  MyStringList := TStringList.Create;
  MyStringList.OnChange := ListChanged;
  ...
end;

hope this helps,
Jeff

Re:how to use events of non-visual components


Thanks for your really fast answer !! These Delphi Newsgroups are the very
best "helpfiles" I've ever seen !!

But one more question:

Quote
> Simple, like this:

> StringList.OnChange := MyChangeHandler;

where do i have to put this line ??

Thanks

Michael

Re:how to use events of non-visual components


aaahhh...got it !!

3 answers within 16 minutes !! really cool ! Thanks

Re:how to use events of non-visual components


On Tue, 29 Feb 2000 23:31:05 +0100, "Michael Ahlers" <M.Ahl...@gmx.de>
wrote:

Quote
> where do i have to put this line ?

Before you want your event-handler method to be active.
--
Rick Rogers (TeamB)
www.fenestra.com and www.componentfactory.com

Other Threads