H
hgptm
Unregistered / Unconfirmed
GUEST, unregistred user!
請見如下:
unit UDPData;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,NMUDP;
type
TReceiveDataEvent = procedure(Recstr:string) of object;
TDummy = class
class procedure onReceiveData(Sender: TComponent; NumberBytes: Integer; FromIP: String; Port: Integer);
end;
TMyUDP = Class
private
FOnReceiveData: TReceiveDataEvent;
public
NMUDP: TNMUDP;
gCurProcessStr: string;
procedure ReceiveData(Recstr:string);
constructor Create;
destructor Destroy; override;
Published
property OnReceiveData: TReceiveDataEvent read FOnReceiveData write FOnReceiveData;
end;
implementation
class Procedure TDummy.onReceiveData(Sender: TComponent; NumberBytes: Integer; FromIP: String; Port: Integer);
var ss: string;
buff: array[0..10] of char;
i: integer;
begin
(Sender as TNMUDP).ReadBuffer(buff, NumberBytes); //
ss:='';
for i:=0 to NumberBytes -1 do
ss:= ss + buff;
// 如何實現 : 將處理結果ss傳給TMyUdp.gCurProcessStr 賓 觸發TMyUdp的OnReceiveData事件????
gCurProcessStr := ss;
//.
end;
constructor TMyUDP.Create;
begin
inherited Create;
NMUDP := TNMUDP.Create(nil);
NMUDP.LocalPort := 8888;
NMUDP.RemotePort := 8080;
NMUDP.RemoteHost := '127.0.0.1';
NMUDP.OnDataReceived := TDummy.onReceiveData;
end;
destructor TMyUDP.Destroy;
begin
if NMUDP <> nil then
begin
FreeAndnil(NMUDP);
end;
inherited;
end;
procedure TMyUDP.ReceiveData(Recstr:string);
begin
if Assigned(FOnReceiveData) then FOnReceiveData(gCurProcessStr);
end;
end.
unit UDPData;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,NMUDP;
type
TReceiveDataEvent = procedure(Recstr:string) of object;
TDummy = class
class procedure onReceiveData(Sender: TComponent; NumberBytes: Integer; FromIP: String; Port: Integer);
end;
TMyUDP = Class
private
FOnReceiveData: TReceiveDataEvent;
public
NMUDP: TNMUDP;
gCurProcessStr: string;
procedure ReceiveData(Recstr:string);
constructor Create;
destructor Destroy; override;
Published
property OnReceiveData: TReceiveDataEvent read FOnReceiveData write FOnReceiveData;
end;
implementation
class Procedure TDummy.onReceiveData(Sender: TComponent; NumberBytes: Integer; FromIP: String; Port: Integer);
var ss: string;
buff: array[0..10] of char;
i: integer;
begin
(Sender as TNMUDP).ReadBuffer(buff, NumberBytes); //
ss:='';
for i:=0 to NumberBytes -1 do
ss:= ss + buff;
// 如何實現 : 將處理結果ss傳給TMyUdp.gCurProcessStr 賓 觸發TMyUdp的OnReceiveData事件????
gCurProcessStr := ss;
//.
end;
constructor TMyUDP.Create;
begin
inherited Create;
NMUDP := TNMUDP.Create(nil);
NMUDP.LocalPort := 8888;
NMUDP.RemotePort := 8080;
NMUDP.RemoteHost := '127.0.0.1';
NMUDP.OnDataReceived := TDummy.onReceiveData;
end;
destructor TMyUDP.Destroy;
begin
if NMUDP <> nil then
begin
FreeAndnil(NMUDP);
end;
inherited;
end;
procedure TMyUDP.ReceiveData(Recstr:string);
begin
if Assigned(FOnReceiveData) then FOnReceiveData(gCurProcessStr);
end;
end.