manganzon
asked on
sending record through sockets
Hi, I'm trying to send a record through sockets.
I have a record TLogin:
type
TStatus=(online,cacona,off line,busy, passedout) ;
PLogin=^TLogin;
TLogin=record
Login:string;
Pass:string;
Status:TStatus;
Display:TPicture;
end;
and I want to Send a var of this record using SendBuf but when the server recive the buffer...
First I tried to do this:
Client:
var log:TLogin;
log.Login:='jojo'
Client.Socket.SendBuff(log , SIzeof(log));
Server
var Buffer:TLogin;
while socket.ReceiveLength>0 do begin
Socket.ReceiveBuf(Buffer, Sizeof(Buffer));
end;
but it didnt work, then I found a code like this:
procedure SendDataStruct(Socket: TCustomWinSocket);
var
joy: TLogin;
begin
Client.socket.SendBuf(@joy , sizeof(joy));
end;
Server:
var Log:PLogin;
Socket.ReceiveBuf(Log^, sizeof(TLogin));
end;
but I got an error at this line: Client.socket.SendBuf(@joy , sizeof(joy)); it says that Im passing a constant object as a parameter.
Anyone know how to solve this problem?
I have a record TLogin:
type
TStatus=(online,cacona,off
PLogin=^TLogin;
TLogin=record
Login:string;
Pass:string;
Status:TStatus;
Display:TPicture;
end;
and I want to Send a var of this record using SendBuf but when the server recive the buffer...
First I tried to do this:
Client:
var log:TLogin;
log.Login:='jojo'
Client.Socket.SendBuff(log
Server
var Buffer:TLogin;
while socket.ReceiveLength>0 do begin
Socket.ReceiveBuf(Buffer, Sizeof(Buffer));
end;
but it didnt work, then I found a code like this:
procedure SendDataStruct(Socket: TCustomWinSocket);
var
joy: TLogin;
begin
Client.socket.SendBuf(@joy
end;
Server:
var Log:PLogin;
Socket.ReceiveBuf(Log^, sizeof(TLogin));
end;
but I got an error at this line: Client.socket.SendBuf(@joy
Anyone know how to solve this problem?
you cannot sent this record since there is an object in there (TPicture).
You cannot just sent an object.
You cannot just sent an object.
ASKER
I've tried both solution, but still have errors. When the server try to use the buffer I got a Read Memory error.
server:
procedure TfrmServer.ServerMainClien tRead(Send er: TObject;
Socket: TCustomWinSocket);
var
log:PLogin;
vildoso:TLogin;
begin
while socket.ReceiveLength>0 do begin
Socket.ReceiveBuf(Log^, sizeof(TLogin));
end;
Showmessage(Log^.Login);// Error here
vildoso:=log^;//Error here
Showmessage(vildoso.Login) ;//Error Here
end;
server:
procedure TfrmServer.ServerMainClien
Socket: TCustomWinSocket);
var
log:PLogin;
vildoso:TLogin;
begin
while socket.ReceiveLength>0 do begin
Socket.ReceiveBuf(Log^, sizeof(TLogin));
end;
Showmessage(Log^.Login);//
vildoso:=log^;//Error here
Showmessage(vildoso.Login)
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
btw, there are many ways to do this, this is just one method.
excuse typos, etc
Loki
excuse typos, etc
Loki
procedure SendDataStruct(Socket: TCustomWinSocket);
var
joy: TLogin;
joyp: PLogin;
begin
...
joyp := @joy;
Client.socket.SendBuf(joyp
end;