Link to home
Start Free TrialLog in
Avatar of Rob Rietow
Rob Rietow

asked on

How do I structure an On.. event for a create Component which requires a value?

I am creating a the below:
    IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := SSLStatus;
I have created a procedure for the SSLStatus:
procedure SSLStatus(const AMsg: string);
begin
  if workswitch then
    frmMain.memo1.Lines.add('SSL Status:'+AMsg);
end;
I get syntaxed :
[dcc32 Error] Global.pas(10162): E2009 Incompatible types: 'method pointer and regular procedure'

This is an example for a like component on a form:
procedure TfrmMain.IdSSLIOHandlerSocketOpenSSL1StatusInfo(const AMsg: string);
begin
  if workswitch then
    memo3.Lines.add('SSL Status:'+AMsg);
end;




(const AMsg: string);
Having issues with a piece of software that relies on a connection to a specific SSID using a wireless USB NIC. The software relies on data sent to the computer from a scanning tool that connects to the same network as the computer. We have problems with Windows Autoconnect working with the adapters we provide to the clients. Looking for a way to check if the connection is working, and if it’s not, to connect the wireless adapter to the SSID when the software is started. I'm using VB.net and C#.

[dcc32 Error] Global.pas(10162): E2009 Incompatible types: 'method pointer and regular procedure'
[dcc32 Warning] Global.pas(10816): W1058 Implicit string cast with potential data loss from 'string' to 'ShortString'
I am creating a the below:<br>&nbsp; &nbsp; IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);<br>&nbsp; &nbsp; IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := SSLStatus;<br>I have created a procedure for the SSLStatus:<br>procedure SSLStatus(const AMsg: string);<br>begin<br>&nbsp; if workswitch then<br>&nbsp; &nbsp; frmMain.memo1.Lines.add(&#39;SSL Status:&#39;+AMsg);<br>end;<br>I get syntaxed :<br>[dcc32 Error] Global.pas(10162): E2009 Incompatible types: &#39;method pointer and regular procedure&#39;<br><br>This is an example for a like component on a form:<br>procedure TfrmMain.IdSSLIOHandlerSocketOpenSSL1StatusInfo(const AMsg: string);<br>begin<br>&nbsp; if workswitch then<br>&nbsp; &nbsp; memo3.Lines.add(&#39;SSL Status:&#39;+AMsg);<br>end;<br><br><br><br><br>(const AMsg: string);

How do I structure  an On.. event for a create Component which requires a value?

        Asked by: Rob Rietow     I am creating a the below:
    IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
    IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := SSLStatus;
I have created a procedure for the SSLStatus:
procedure SSLStatus(const AMsg: string);
begin
  if workswitch then
    frmMain.memo1.Lines.add('SSL Status:'+AMsg);
end;
I get syntaxed :
[dcc32 Error] Global.pas(10162): E2009 Incompatible types: 'method pointer and regular procedure'

This is an example for a like component on a form:
procedure TfrmMain.IdSSLIOHandlerSocketOpenSSL1StatusInfo(const AMsg: string);
begin
  if workswitch then
    memo3.Lines.add('SSL Status:'+AMsg);
end;
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Little messy question text... or EE breaks somewhere...

Put SSLStatus as TForm class - this makes that procedure act as method. There is another way - but this one should be sufficient.

Sinisa is right. He means that you should declare SSLStatus in class or private section of TfrmMain
and code it as
procedure TfrmMain.SSLStatus(const AMsg: string);
begin
  if workswitch then
    memo1.Lines.add('SSL Status:'+AMsg);
end;

Open in new window


Avatar of Rob Rietow
Rob Rietow

ASKER

Let me try again.  I am trying to create an ON procedure for  a created component.  All of this is in a Unit, not on a Form.

I create the Component and want to assign a procedure to the OnStatusInfo event

Procedure HandleEmailMessages;
begin
…...
 IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
 IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := SSLStatus;
….
end;

Then I create a procedure for the SSLStatus:

procedure SSLStatus;
begin
   // do something
end;

I get syntaxed :
[dcc32 Error] Global.pas(10162): E2009 Incompatible types: 'method pointer and regular procedure'

Your component is surely a class. Put your procedure under a component class. Ferruccio gave an example.
If this is not a class - then this is not a component. Maybe you want a single standalone unit?
This in a Unit, not a Form.  There is no class(TForm) statement.

In this Unit I am trying to do the following:  

    idSMTP1 := TIdSMTP.create(nil);
    IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);

    //IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := SSLStatus;  <<<<<<<<<<<<<<<< (Procedure)

    idSMTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    idMessage1 := TidMessage.create(nil);


SO in a unit you have to address the procedure of object
something like this
unit Unit2;

interface

uses
  forms, IdBaseComponent, IdComponent, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdTCPConnection, IdTCPClient,
  IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP;
procedure CreateIDSSL;
procedure SSLStatus(const AMsg: string);

var
  idSMTP1: TIDSMTP;
  IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
  workswitch: boolean;
implementation

uses unit1;

procedure SSLStatus(const AMsg: string);
begin
  if workswitch then
    frmMain.memo1.Lines.add('SSL Status:'+AMsg);
end;

procedure CreateIDSSL;
begin
  idSMTP1 := TIDSMTP.Create(nil);
  IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  IdSSLIOHandlerSocketOpenSSL1 := @SSLStatus; //<-- the @ addresses to the proc
end;

end.

Open in new window

When you don't have class to put method in, there is another trick. Create dummy class like TMyid_EventHandlers:
type
  TMyid_EventHandlers = class
    procedure SSLStatus(const AMsg: string);
  end;

var
  Myid_EventHandlers: TMyid_EventHandlers;

{ TMyid_EventHandlers }

procedure TMyid_EventHandlers.SSLStatus(const AMsg: string);
begin
  ...
end;

...
IdSSLIOHandlerSocketOpenSSL1.OnStatusInfo := Myid_EventHandlers.SSLStatus; 
...

Open in new window


This way should work. Request is that SSLStatus is defined exactly as OnStatusInfo event.
I am missing something. I am getting syntaxed.

[dcc32 Error] Global3.pas(36): E2004 Identifier redeclared: 'Myid_EventHandlers'

type
  TMyid_EventHandlers = class
    procedure SSLStatus(const AMsg: string);
  end;

var
  Myid_EventHandlers: TMyid_EventHandlers;
  procedure Myid_EventHandlers.SSLStatus(const AMsg: string);

  function SendGeneralEmail(vEmailRecord: TEmailRecord): boolean;
  function GetComputerNetName: string;
var
  workswitch: boolean;
implementation
uses FMain;
procedure Myid_EventHandlers.SSLStatus(const AMsg: string);
begin
  //
end;

Errors messages usually tell what's wrong

You've declared procedure Myid_EventHandlers.SSLStatus(const...
Instead of procedure TMyid_EventHandlers.SSLStatus(const...
I am not familiar with this area of coding.  Please correct the actual code.  I have tried what I think you mean without any success.

did you try as I suggested above? Just pointing to your procedure in your unit using @SSLStatus ?
[dcc32 Error] Global3.pas(36): E2004 Identifier redeclared: 'TMyid_EventHandlers.SSLStatus'

type
  TMyid_EventHandlers = class
    procedure SSLStatus(const AMsg: string);
  end;
var
  Myid_EventHandlers: TMyid_EventHandlers;
  procedure TMyid_EventHandlers.SSLStatus(const AMsg: string);

  function SendGeneralEmail(vEmailRecord: TEmailRecord): boolean;
  function GetComputerNetName: string;
var
  workswitch: boolean;
implementation
uses FMain;
procedure Myid_EventHandlers.SSLStatus(const AMsg: string);
begin
  //
end;

ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
TMyid_EventHandlers is a class and have a procedure
Then you declare a var of type TMyid_eventhandlers to use it

THANK YOU!
Rob, you are new in Delphi? Seems - yes because I miss to put 'T' in front of class implementation and you did not noticed that. Try to learn basics first. You'll need it.
And please try to edit/remove this text before your actual question. It is confusing..
Not new to Delphi but am new to creating classes in a unit.  I have been writing since Delph 3 and have not had the need.