这样写不对吗?(50分)

  • 主题发起人 主题发起人 meilixueshan200
  • 开始时间 开始时间
M

meilixueshan200

Unregistered / Unconfirmed
GUEST, unregistred user!
TMyBlock=record
m_username:string[16];
 SendToName:string[16];
m_stream:TStream;
end;
m_username是自己的用户名,SendToName是接收者的用户名,m_stream用来存储视频和音频流?
这样写不对吗?
如果不对,请问怎么写?
 
TMyBlock=record
m_username:string;
SendToName:string;
m_stream:TStream;
end;
 
不行呀
去掉字符限制也不行
如果我去掉m_stream:TStream;就可以正常传递,但加上就不行
难道这里面不能定义TStream类型?
 
同意二楼
 
对的………………
 
我刚才复制的时候发现里面有一个全角的空格,删掉它!
 
procedure TClientForm.GrabberBuffer(sender: TObject; SampleTime: Double; pBuffer: Pointer; BufferLen: Integer);
var
Stream: TStream;
MyBlock:TMyBlock;
begin
Stream:=TStream.Create;
MyBlock.m_username:='brucelee';
try
if VideoWindow.VMRGetBitmap(Stream) then
begin
image.Picture.Bitmap.LoadFromStream(Stream);
MyBlock.m_stream:=Stream;
end;
Grabber.GetBitmap(Image1.Picture.Bitmap);
finally
Stream.Free;
end;

if ConnectForm.TCPClient.Connected then
begin
try
ConnectForm.TCPClient.WriteBuffer(MyBlock,SizeOf(MyBlock),true);
except
end;
end;
end;
服务端:
procedure TServerForm.TCPServerExecute(AThread: TIdPeerThread);
var
jpg: TJpegImage;
MyBlock:TMyBlock;
getstream:TStream;
begin
if AThread.Connection.Connected and not AThread.Terminated then
begin
getstream:=TStream.Create;
AThread.Connection.ReadBuffer(MyBlock,SizeOf(MyBlock));
listbox1.Items.Add(MyBlock.m_username);
getstream.CopyFrom(MyBlock.m_stream,SizeOf(MyBlock.m_stream));
getstream.Position:=0;
jpg := TJpegImage.Create;
jpg.LoadFromStream(getstream);
Image.Picture.Bitmap.Assign(jpg);
jpg.Free;
getstream.Free;
end;
end;
为什么服务端收不到?
 
错:不能实例化TStream类
getstream:=TStream.Create;
Stream:=TStream.Create;
改: := TMemoryStream.Create;
 
我改为TMemoryStream为什么还不行?
if ConnectForm.TCPClient.Connected then
begin
try
ConnectForm.TCPClient.WriteBuffer(MyBlock,SizeOf(MyBlock),true);
except
end;
end;
根本不能传送,如果把try...except end;去掉去出错
如果不去掉,只能把MyBlock.m_username:='brucelee';传过去,
stream传不过去,或是说接不到
 
stream不能直接传,事实上你只传了stream的指针,到了对方是无效指针
ConnectForm.TCPClient.WriteBuffer(MyBlock,SizeOf(MyBlock),true);
ConnectForm.TCPClient.WriteBuffer(MyBlock.memory,stream.size,true);
 
楼上的意思是要传两次?
MyBlock.memory什么意思
 
MyBlock.memory才是实际的你存在stream内的数据
加上m_username, SendToName, 他们的地址不连续,所以要发二次
 
错了,应该是MyBlock.memory^
 
MyBlock.memory?
是MyBlock.m_stream吧?
如果是MyBlock.memory,那么提示出错
可是我改成MyBlock.m_stream后,依然传不过去呀
 
MyBlock.m_stream.memory^
 
传不过去
关闭窗口时还提示“Access violation at address 00E0495D. Write of address FFFFFF00”错误
 
Stream:=TStream.Create;
MyBlock.m_username:='brucelee';
try
if VideoWindow.VMRGetBitmap(Stream) then
begin
image.Picture.Bitmap.LoadFromStream(Stream);
MyBlock.m_stream:=Stream;
end;
Grabber.GetBitmap(Image1.Picture.Bitmap);
finally
Stream.Free; //你这里已经释放掉了
end;
 
服务端这么写为什么收不到呢?
procedure TServerForm.TCPServerExecute(AThread: TIdPeerThread);
var
jpg: TJpegImage;
userBlock:TUserBlock;
getstream:TMemoryStream;
begin
if AThread.Connection.Connected and not AThread.Terminated then
begin
getstream:=TMemoryStream.Create;
AThread.Connection.ReadBuffer(userBlock.m_stream.memory^,userBlock.m_stream.Size);
jpg := TJpegImage.Create;
jpg.LoadFromStream(getstream);
Image.Picture.Bitmap.Assign(jpg);
jpg.Free;
getstream.Free;
end;
end;
 
TMyBlock=record
m_username:string[16];
 SendToName:string[16];
m_stream:pchar;
end;
 
read就不是userBlock.m_stream.Size了
AThread.Connection.ReadBuffer(userBlock.m_stream.memory^,userBlock.m_stream.Size);
 
后退
顶部