开辟一块内存空间

procedure TForm1.SendFileOnetime(FileName: string);  //一次性发送文件
var trans:file of Byte;
  FileLen:Integer;
  Blockbuff:pointer;
  socket:TCustomWinSocket;
begin
  if(isServer) then socket:=ServerSocket1.Socket else socket:=ClientSocket1.Socket;
  AssignFile(trans,filename);
  Reset(trans);
  FileLen:=FileSize(trans);
  GetMem(Blockbuff,FileLen);
  BlockRead(Trans,Blockbuff^,FileLen);
  socket.SendBuf(Blockbuff^,FileLen);

  FreeMem(Blockbuff);
end;


Blockbuff:pointer;

GetMem(Blockbuff,FileLen);  分配内存

BlockRead(Trans,Blockbuff^,FileLen);

 

你可能感兴趣的:(开辟一块内存空间)