var
aa: array [0..5] of Char;
bb:Pointer;
cc:string;
dd:PChar;
procedure TForm1.Button1Click(Sender: TObject);
begin
dd:='abcdef';
//以下是pchar内容转数组
FillChar(aa,length(dd),#0);
Move(dd^,aa,SizeOf(aa));
//以下是数组传递到指针
bb:=GetMemory(SizeOf(aa));
Move(aa,bb^,SizeOf(aa));
//以下是指针内容传递给字符串
SetLength(cc,SizeOf(aa));
Move(bb^,cc[1],SizeOf(aa));
FreeMemory(bb);//这个是释放内存
//以下是数组转pchar
dd:='';
dd:=PChar(@aa);
MessageBox(0,PChar('cc: '+cc),PChar('dd: '+dd),0);
end;
function Client_Cmd(dwConnID: HP_CONNID; const pData: Pointer; iLength: Integer): Boolean;
var
sCmd: AnsiString;
tmpJSONObject: TJSONObject;
cmdType: DWORD;
tmpRclient: RClient;
begin
try
try
SetLength(sCmd, iLength);
CopyMemory(pAnsichar(sCmd), pData, iLength);
OutputDebugString_MZ(Format('接受到客户端请求%d > %s ', [dwConnID, sCmd]));
tmpJSONObject := TJSONObject.ParseJSONValue(sCmd) as TJSONObject;
if tmpJSONObject <> nil then
begin
cmdType := StrToInt(tmpJSONObject.GetValue('type').Value);
case cmdType of
注册客户端:
begin
//{"type":1,"clientName":'主机名',"mac":'sdfsdfsdf',""}
tmpJSONObject.TryGetValue('clientName', tmpRclient.pcName);
tmpJSONObject.TryGetValue('mac', tmpRclient.mac);
tmpRclient.connID := dwConnID;
// if dm. then
ClientDictionary.AddOrSetValue(tmpRclient.pcName, tmpRclient);
Exit;
end;
end;
end;
except
OutputDebugString_MZ('客户端发包解析异常>' + sCmd);
end;
finally
end;
end;