0
在我解释我的问题之前,我很抱歉我的英语不好。 好的,这里是我的问题。当我的印服务器将位图帧的客户,总是出现警告这样的:为什么当发送位图帧到MemoryStream到客户端时出现警告?
“EAccessViolation地址004DD42A ......”
和错误语法蓝色高亮显示在此:
Athread.Connection.WriteInteger(MemoryStream.Size);
这里我的源代码:
服务器
procedure TFormHome.TCPServerConnect(AThread: TIdPeerThread);
var
NewClient: PClient;
begin
GetMem(NewClient, SizeOf(TClient));
NewClient.PeerIP := AThread.Connection.Socket.Binding.PeerIP;
NewClient.HostName := GStack.WSGetHostByAddr(NewClient.PeerIP);
NewClient.Connected := Now;
NewClient.LastAction := NewClient.Connected;
NewClient.Thread := AThread;
AThread.Data := TObject(NewClient);
try
Clients.LockList.Add(NewClient);
finally
Clients.UnlockList;
end;
procedure TFormHome.TCPServerExecute(AThread: TIdPeerThread);
var
pesan:string;
begin
pesan:=Athread.Connection.ReadLn;
if pesan = 'video' then
begin
Athread.Connection.WriteLn('send');
Timer1.Enabled:=true;
FormStream.Show;
Athread.Connection.WriteInteger(MemoryStream.Size);
Athread.Connection.OpenWriteBuffer;
Athread.Connection.WriteStream(MemoryStream);
AThread.Connection.CloseWriteBuffer;
FreeAndNil(MemoryStream);
FormStream.Image1.Picture.Bitmap.Free;
end;
procedure TFormHome.Timer1Timer(Sender: TObject);
begin
pic := TBitmap.Create;
MemoryStream:=TMemoryStream.Create;
VideoGrabber.GetBitmap(FormStream.image1.Picture.Bitmap);
pic := FormStream.Image1.Picture.Bitmap;
pic.SaveToStream(MemoryStream);
//Pic.Free;
//FreeAndNil(Pic);
end;
CLIENT
procedure TFormClient.TCPClientConnected(Sender: TObject);
var
pesan : string;
begin
IncomingMessages.Lines.Insert(0,'Connected to Server');
TCPClient.WriteLn('video');
pesan := TCPClient.ReadLn;
if pesan = 'send' then Timer1.Enabled:=true;
end;
procedure TFormClient.Timer1Timer(Sender: TObject);
var
Size : integer;
ReadStream : TMemoryStream;
begin
ReadStream := TMemoryStream.Create;
Size := TCPClient.ReadInteger;
TCPClient.ReadStream(ReadStream,Size,True);
Image1.Picture.Bitmap.LoadFromStream(ReadStream);
Image1.Picture.Bitmap.Free;
FreeAndNil(ReadStream);
end;
什么是错的难熬我的代码?我需要你的帮助。
之前谢谢你.. ^^
我有点困惑这个代码:类型 TLogNotify = A类(TIdNotify) 保护 程序DoNotify;覆盖; public Msg:String; 结束; –
当我把这段代码放在初始声明中时,警告出现它找不到TidNotify标识符。 –
'TIdNotify'位于'IdSync.pas'单元中。它是一个工具类,可以帮助工作线程异步地在主线程中运行代码,类似于'TThread.Queue()'。还有一个'TIdSync'类用于在主线程中同步运行代码,类似于TThread.Synchronize()。在大多数Delphi版本中使用'TIdNotify'和'TIdSync'的优点是能够传递数据,TThread.Queue()和TThread.Synchronize()直到最近才引入匿名过程。 –