TIdBytes to String
String str=BytesToString( AValue: TIdBytes);
TMemoryStream to TIdBytes
// 方法一 RawToBytes
// TByteDynArray *barry = new TByteDynArray[MyStream->Size];// barry[0] = RawToBytes(MyStream->Memory, MyStream->Size);
// IdUDPServer1->SendBuffer(edtInput->Text, 137, barry[0]);
// // 方法二 ReadBuffer
// TByteDynArray barry2;
// barry2.set_length(MyStream->Size);
// MyStream->Position = 0;
// MyStream->ReadBuffer(barry2, MyStream->Size);
// IdUDPServer1->SendBuffer(edtInput->Text, 137, barry2);
// // 方法三 ReadBuffer
// TByteDynArray *barry3 = new TByteDynArray;
// barry3->set_length(MyStream->Size);
// MyStream->Position = 0;
// MyStream->ReadBuffer(*barry3, MyStream->Size);
// IdUDPServer1->SendBuffer(edtInput->Text, 137, *barry3);
// 方法4 ReadTIdBytesFromStream
TByteDynArray barry4;
barry4.set_length(MyStream->Size);
MyStream->Position = 0;
ReadTIdBytesFromStream(MyStream,barry4,MyStream->Size);
IdUDPServer1->SendBuffer(edtInput->Text, 137, barry4);
TIdBytes to TMemoryStream
// WriteTIdBytesToStream(MyStream, AData, ilen);
MyStream->WriteData(AData,ilen);
struct to TIdBytes
typedef struct person
{
int id;
AnsiString name;
}tsperson;
TByteDynArray arr;
tsperson ps;
tsperson ps2;
ps.id = 1;
ps.name = "kitty";
arr = RawToBytes(&ps,sizeof(tsperson));
//Move(&ps,&arr[0],sizeof(tsperson));
//MoveMemory(&arr[0],&ps,sizeof(tsperson));
//memcpy(&arr[0],&ps,sizeof(tsperson));
四种方法都可以
TIdBytes to struct
BytesToRaw(arr,&ps2,arr.Length);
// Move(&arr[0],&ps2,arr.Length);
MoveMemory(&ps2,&arr[0],sizeof(tsperson));
//memcpy(&ps2,&arr[0],arr.Length);
四种方法都可以