高手搭救一下吧...................
type
DataPack = record
DataPackFlag: LongInt;
DataPackCurrLength:LongInt;
DataPackInfo: array[1..1000] of Char;
end;
//此处定义数据结构记录变量类型
//**************************
function CommonSendPacket(ServerSock: Tsocket; pBuffer: Pchar;iDatalength: Integer): Integer; stdcall;
var
tmp_iSendBytes: Integer;
tmp_iTotalBytes: Integer;
begin
tmp_iSendBytes := 0;
tmp_iTotalBytes := 0;
if ServerSock = SOCKET_ERROR then
begin
CommonSendPacket := 0;
Exit;
end
else
begin
while (tmp_iSendBytes < iDatalength) do
begin
//调试发现此处的pbuffer为什么不是传递参数指针所指向的内存区域呢?
//c语言c++不都是传递指针就可以了。
tmp_iSendBytes := send(ServerSock, pBuffer, iDatalength - tmp_iTotalBytes, 0);
if tmp_iSendBytes > 0 then
begin
pBuffer := pBuffer + tmp_iTotalBytes;
tmp_iTotalBytes := tmp_iTotalBytes + tmp_iSendBytes;
end
else
begin
CommonSendPacket := tmp_iTotalBytes;
Exit;
end
end;
Result := tmp_iTotalBytes;
end
end;
//*********************此处封装的通用数据发送函数
//下面的函数调用此函数发送数据
//m_DataPackSend为DataPack类型变量。数据已经填充好。
function SendSystemDataPacket(): Integer; stdcall;
var
tmp_iBytesCounts:Integer;
begin
GetUserInfo;
FillDataPack;
tmp_iBytesCounts := 0;
//注意此处的m_DataPackSend类型包含数据,函数传递指针。
tmp_iBytesCounts:=CommonSendPacket(m_hServerSocket,@m_DataPackSend, m_DataPackSend.DataPackCurrLength);
SendSystemDataPacket := tmp_iBytesCounts;
end;
//**********************
//请问我要实现函数之间传递那个记录类型变量。而且我想要的是引用的方式。
请问怎么操作???
[解决办法]
什么叫引用的方式?指针么?
[解决办法]
procedure test(var a:Ta);
参数+ var
[解决办法]
利用var 引用的方式
等价于指针的传递。。
你就可以使用了。。
记得在用的时候注意 dest srouce
function CommonSendPacket(ServerSock: Tsocket; pBuffer: Pchar;iDatalength: Integer): Integer; stdcall;
var
tmp_iSendBytes: Integer;
tmp_iTotalBytes: Integer;
begin
tmp_iSendBytes := 0;
tmp_iTotalBytes := 0;
if ServerSock = SOCKET_ERROR then
begin
CommonSendPacket := 0;
Exit;
end
else
begin
while (tmp_iSendBytes < iDatalength) do
begin
//调试发现此处的pbuffer为什么不是传递参数指针所指向的内存区域呢?
//c语言c++不都是传递指针就可以了。
tmp_iSendBytes := send(ServerSock, pBuffer, iDatalength - tmp_iTotalBytes, 0);
if tmp_iSendBytes > 0 then
begin
pBuffer := pBuffer + tmp_iTotalBytes;
tmp_iTotalBytes := tmp_iTotalBytes + tmp_iSendBytes;
end
else
begin
CommonSendPacket := tmp_iTotalBytes;
Exit;
end
end;
Result := tmp_iTotalBytes;
end
end;
//*********************此处封装的通用数据发送函数