Re: [twsocket] TWSocketClient inheritance problem

2005-08-23 Thread Wilfried Mestdagh
Hello Snake,

You are typecasting the server as your clientclass instead of the
client. It should be:

procedure TFrmTest.ServClientConnect(Sender: TObject; Client: TWSocketClient;
  Error: Word);
begin
//  TWSockClient(Sender).MyEvent := Test; // wrong
  TWSockClient(Client).MyEvent := Test;   // right
end;

One other advice: dont use modal forms for testing, use WriteLn instead.
Calling message pump will do let you search for errors that arent there.

---
Rgds, Wilfried
http://www.mestdagh.biz

Tuesday, August 23, 2005, 07:39, Snake Liquid wrote:

> hello,
 
> i have defined a small class for ClientClass to use with
> TWSocketServer wich have an event that it should call, but i remarked
> that when the server try to call TriggerClientCreate(Client); in the
> TriggerSessionAvailable method, it calls my event ..
 
> here is the class :
 
> unit Test;
> interface
> uses
>   Classes, WSocketS;
> type
>   TMyEvent = procedure (Sender: TObject; const AnObject: TObject) of object;
>   TWSockClient = class(TWSocketClient)
>   protected
> FMyEvent: TMyEvent;
> procedure DataReceived(Sender: TObject; ErrCode: Word);
>   published
> constructor Create(AOwner: TComponent); override;
> property MyEvent: TMyEvent read FMyEvent write FMyEvent;
>   end;
> implementation
> constructor TWSockClient.Create(AOwner: TComponent);
> begin
>   inherited Create(AOwner);
>   OnDataAvailable := DataReceived;
> end;
> procedure TWSockClient.DataReceived(Sender: TObject; ErrCode: Word);
> begin
>   //Some job to do
>   Text;
>   if Assigned(FMyEvent) then
> FMyEvent(Sender, nil);
> end;
> end.

 
 
 
 
 
> and here is a small test 
 
> procedure TFrmTest.Test(Sender: TObject; const Obj: TObject);
> begin
>   ShowMessage('ok');
> end;

> procedure TFrmTest.ServClientConnect(Sender: TObject; Client: TWSocketClient;
>   Error: Word);
> begin
>   TWSockClient(Sender).MyEvent := Test;
> end;

 
 
 
> just implement this in a form and try to connect the first time to
> the server, everything will be done correctly, but in the next
> connection, the server will call Test when he calls TriggerClientCreate
 
> any idea please, if you need me to prepare all the units in an example, just 
> told me.


> -
>  Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
>  Téléchargez le ici !  

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocketClient inheritance problem

2005-08-22 Thread Francois Piette
> constructor TWSockClient.Create(AOwner: TComponent);
> begin
>   inherited Create(AOwner);
>   OnDataAvailable := DataReceived;
> end;

When you derive from a component, you should _not_ use the OnSomeEvent 
properties. Instead, you have
to override the procedure, usually named TriggerSomeEvent, that triggers the 
event in the parent
class and still call the external event handler.

> procedure TFrmTest.Test(Sender: TObject; const Obj: TObject);
> begin
>   ShowMessage('ok');
> end;

In an event handler that has his source from hardware, such as OnDataAvailable, 
you can't call the
message pump directly (ProcessMessages) or indirectly (ShowMessage and many 
others). This is because
when the message pump is called, the pending events are triggered and the event 
handler are
re-entered, causing many troubles.

If you want to display something, add a line to a TMemo, use OutputDebugString, 
write a line to a
console or to a log file. But do _not_ call a modal form.

--
Contribute to the SSL Effort. Visit
http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be



- Original Message - 
From: "Snake Liquid" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, August 23, 2005 7:39 AM
Subject: [twsocket] TWSocketClient inheritance problem


> hello,
>
> i have defined a small class for ClientClass to use with TWSocketServer wich 
> have an event that it
should call, but i remarked that when the server try to call 
TriggerClientCreate(Client); in the
TriggerSessionAvailable method, it calls my event ..
>
> here is the class :
>
> unit Test;
> interface
> uses
>   Classes, WSocketS;
> type
>   TMyEvent = procedure (Sender: TObject; const AnObject: TObject) of object;
>   TWSockClient = class(TWSocketClient)
>   protected
> FMyEvent: TMyEvent;
> procedure DataReceived(Sender: TObject; ErrCode: Word);
>   published
> constructor Create(AOwner: TComponent); override;
> property MyEvent: TMyEvent read FMyEvent write FMyEvent;
>   end;
> implementation
> constructor TWSockClient.Create(AOwner: TComponent);
> begin
>   inherited Create(AOwner);
>   OnDataAvailable := DataReceived;
> end;
> procedure TWSockClient.DataReceived(Sender: TObject; ErrCode: Word);
> begin
>   //Some job to do
>   Text;
>   if Assigned(FMyEvent) then
> FMyEvent(Sender, nil);
> end;
> end.
>
>
>
>
>
>
> and here is a small test
>
> procedure TFrmTest.Test(Sender: TObject; const Obj: TObject);
> begin
>   ShowMessage('ok');
> end;
>
> procedure TFrmTest.ServClientConnect(Sender: TObject; Client: TWSocketClient;
>   Error: Word);
> begin
>   TWSockClient(Sender).MyEvent := Test;
> end;
>
>
>
>
> just implement this in a form and try to connect the first time to the 
> server, everything will be
done correctly, but in the next connection, the server will call Test when he 
calls
TriggerClientCreate
>
> any idea please, if you need me to prepare all the units in an example, just 
> told me.
>
>
> -
>  Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
>  Téléchargez le ici !
> -- 
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://www.elists.org/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be