Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-09-2001, 01:22 PM
b-w-d.net b-w-d.net is offline
Senior Member
 
Join Date: May 2001
Posts: 1,122
Default Whats wrong with this code?

program TNTwist;

uses
Forms,ScktComp,SysUtils,Dialogs;

{$R *.RES}

var
server: TServerSocket;
Client: TCustomWinSocket;
Command: String;
DontClose: Boolean = True;

procedure serverClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
beep;
end;

procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
beep;
end;


begin
Server := TServerSocket.Create(nil);
Server.OnClientConnect := ServerClientConnect;
Server.OnClientRead := serverClientRead;
Server.Active := True;
while DontClose do Application.ProcessMessages;
Server.Free;
end.

its getting errors on the lines:
Server.OnClientConnect := ServerClientConnect;
Server.OnClientRead := serverClientRead;

and says that
Incompatible types: method pointer and regular procedure

thanks in advance.

see you around, bye!

----------------------------
[http://b-w-d.net]
webmaster@b-w-d.net
[if this helps you please click on Accept]

Anyone who is interested in webbot, general TCP/IP client development or converting C++ code to Delphi code please contact admin@b-w-d.net
currently working on: Yahoo!Chat integration controls
Reply With Quote
  #2  
Old 11-09-2001, 01:45 PM
B at work B at work is offline
Senior Member
 
Join Date: Oct 2001
Posts: 421
Default RE: Whats wrong with this code?

try something like this:

program bwdnet;

uses
Forms, ScktComp, SysUtils, Dialogs, Classes;

{$R *.RES}

type
TMyObject = class(TComponent)
public
server : TServerSocket;
Client : TCustomWinSocket;
Command : string;
constructor create(AOwner: TComponent); override;
destructor destroy; override;
procedure serverClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
end;

constructor TMyObject.Create(AOwner : TComponent);
begin
Server := TServerSocket.Create(nil);
Server.OnClientConnect := ServerClientConnect;
Server.OnClientRead := serverClientRead;
Server.Active := True;
inherited;
end;

destructor TMyObject.destroy;
begin
Server.Free;
inherited;
end;

procedure TMyObject.serverClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
beep;
end;

procedure TMyObject.ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
beep;
end;

var
MyObject : TMyObject;
DontClose : Boolean = True;


begin
MyObject.Create(nil);
while DontClose do Application.ProcessMessages;
MyObject.Free;
end.

eventhandlers must be methodes, not procedures, means:
they need to be part of an object. this code will compile, but runs into an address trap...

cu, B
Reply With Quote
  #3  
Old 11-09-2001, 02:36 PM
b-w-d.net b-w-d.net is offline
Senior Member
 
Join Date: May 2001
Posts: 1,122
Default RE: Whats wrong with this code?

if you could work out how to stop the access violaation then that would be great.

see you around, bye!

----------------------------
[http://b-w-d.net]
webmaster@b-w-d.net
[if this helps you please click on Accept]

Anyone who is interested in webbot, general TCP/IP client development or converting C++ code to Delphi code please contact admin@b-w-d.net
currently working on: Yahoo!Chat integration controls
Reply With Quote
  #4  
Old 11-09-2001, 02:41 PM
B at work B at work is offline
Senior Member
 
Join Date: Oct 2001
Posts: 421
Default RE: Whats wrong with this code?

Hmm, what OS do you use?
Reply With Quote
  #5  
Old 11-09-2001, 04:08 PM
b-w-d.net b-w-d.net is offline
Senior Member
 
Join Date: May 2001
Posts: 1,122
Default RE: Whats wrong with this code?

win98

see you around, bye!

----------------------------
[http://b-w-d.net]
webmaster@b-w-d.net
[if this helps you please click on Accept]

Anyone who is interested in webbot, general TCP/IP client development or converting C++ code to Delphi code please contact admin@b-w-d.net
currently working on: Yahoo!Chat integration controls
Reply With Quote
  #6  
Old 11-09-2001, 04:14 PM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: Whats wrong with this code?

Compiles perfect and doesn't give any exceptions runtime:

program TNTwist;

uses
Forms,ScktComp,SysUtils,Dialogs;

type TMyEvents = class
procedure ServerClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
end;

procedure TMyEvents.ServerClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
beep;
end;

procedure TMyEvents.ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
beep;
end;

var
server: TServerSocket;
Client: TCustomWinSocket;
Command: String;
DontClose: Boolean = True;
Events: TMyEvents;
begin
Server := TServerSocket.Create(nil);
Server.OnClientConnect := Events.ServerClientConnect;
Server.OnClientRead := Events.ServerClientRead;
Server.Active := True;
while DontClose do Application.ProcessMessages;
Server.Free;
end.


Hope that helps...

gLes

"Small step for me, but large step for all Delphi developers!"
/gLes@hab.hu/

Remeber all who have died at the WTC and let those responsible get the punishment they deserve!
Reply With Quote
  #7  
Old 11-09-2001, 04:20 PM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: Whats wrong with this code?

Win98 rulez!!!

gLes

"Small step for me, but large step for all Delphi developers!"
/gLes@hab.hu/

Remeber all who have died at the WTC and let those responsible get the punishment they deserve!
Reply With Quote
  #8  
Old 11-10-2001, 04:57 AM
b-w-d.net b-w-d.net is offline
Senior Member
 
Join Date: May 2001
Posts: 1,122
Default RE: Whats wrong with this code?

OH I LOVE YOU! lol, jus kidding, i hate using forms when i dont need to, makes a project look cheap.

thanks LOADS, wonderful stuff.

see you around, bye!

----------------------------
[http://b-w-d.net]
webmaster@b-w-d.net
[if this helps you please click on Accept]

Anyone who is interested in webbot, general TCP/IP client development or converting C++ code to Delphi code please contact admin@b-w-d.net
currently working on: Yahoo!Chat integration controls
Reply With Quote
  #9  
Old 11-10-2001, 06:11 AM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: Whats wrong with this code?

Hey...you're welcome...

gLes

"Small step for me, but large step for all Delphi developers!"
/gLes@hab.hu/

Remeber all who have died at the WTC and let those responsible get the punishment they deserve!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:56 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.