Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set event handler at runtime

Status
Not open for further replies.

MatthiasB

IS-IT--Management
Oct 19, 2002
72
DE
Hi,

I wrote a mini form-app that connects to an SMTP server and sends an email - using this for batch job control. I want to go away from the form and make it a console application. My problem is that I cannot assign the event handlers for connect, failure, and success like I can do in the form version (type is TNMSMTP) - here's a small test:

Code:
program Project1;
{$APPTYPE CONSOLE}
uses SysUtils,NMSMTP;

var
  SMTP: TNMSMTP;

procedure SMTPConnect(Sender: TObject);
begin
  SMTP.SendMail;
end;

begin
  //--  set event handler
  SMTP.OnConnect := SMTPConnect;
  SMTP.Connect;
end.

The error message is
Code:
"Incompatible types: method pointer and regular procedure"
. What is the best way to make my procedure a method - should I wrap the functions into a 'dummy' object?

Also, since I have to wait for the final event success ot failure before closing the application, what is the best way of doing that? I have to put some code after the
Code:
SMTP.Connect
, or the application will stop before it sent the mail, right?

Thanks,
Matthias
 
Event handlers are normally object procedures--it's expected that they will be declared on your form. If you truly have no object to put them in then you'll need to make a dummy. However, I would look with considerable skepticism at such code.

Note also that you seem to be using the NetMasters components. These aren't very good, lots of bugs, haven't been updated in ages, and have been dropped from Delphi 7.
 
Hi Loren,

got it working now - made a new class(TObject) that includes an NMSMTP attribute, then assigned all event handlers. So far no problems, works smoothly and send all mails.

What replacement for NM components do you suggest? So far haven't seen any complete set yet, only subsets like in JEDI.

Thanks,
Matthias
 
I've been using INDY 9 (8 has some problems) and have no serious gripes with it. The only problem it's giving me is a display one--the routine that's supposed to keep your window responsive is sometimes not working, making the program *APPEAR* locked up.

It's the *ONLY* library I've tried that I can reliably send and receive attachments with.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top