Using TIdDecoder.DecodeBegin() is the correct way to decode to a TStream. However, you do not need the intermediate TIdMemoryStream (which, BTW, has not existed in Indy 10 for a long time now - consider upgrading to a newer release). You can pass the Blob stream directly instead, for example:
var
BlobElement : TBATypedBlob;
BlobStreamStr : String;
BlobStream : TStream;
MIMEDecoder : TidDecoderMIME;
begin
...
if BoldElement is TBATypedBlob then
begin
BlobElement := BoldElement as TBATypedBlob;
BlobStreamStr := Copy(ChangeValue, Pos(']',ChangeValue)+1, Maxint);
BlobElement.ContentType := Copy(ChangeValue, 2, Pos(']',ChangeValue)-2);
BlobStream := BlobElement.CreateBlobStream(bmWrite);
try
MIMEDecoder := TidDecoderMIME.Create(nil);
try
MIMEDecoder.DecodeBegin(BlobStream);
try
MIMEDecoder.Decode(BlobStreamStr);
finally
MIMEDecoder.DecodeEnd;
end;
finally
FreeAndNil(MIMEDecoder);
end;
finally
FreeAndNil(BlobStream);
end;
end;
...
end;
you have a method with same name
procedure TIdUDPClient.SendBuffer(const AHost: string; const APort: TIdPort;
const ABuffer: TIdBytes);
Instead of an untyped buffer it expects an array of bytes. What is your data like? You just need to write your data as an array of bytes. Something like:
var
Buffer: TIdBytes;
begin
SetLength(Buffer, YourSizeOfData);
Move(YourData, Buffer[0], YourSizeOfData);
FIdUDPClient.SendBuffer('255.255.255.255', UIPerfPort, Buffer);
end;
But as I said it depends on the type of the data. The approach is ok however.
EDIT:
Now that I can see that you have a record you have two options:
Just move the whole record to array of bytes.
Move(@aRecord, Buffer[0], (6 + TimeClassMax) * SizeOf(Integer));
Have a CopyToBytes method in your record that does the actual copy. More general I guess.
TTimeDataRecord = record
Size: Integer; //Size of record structure is transfered and compared for safty reasons.
ClientCount: Integer;
AccumulatedTime: Integer; //This is the accumulated time busy in microseconds
CurrentMessageTime: Integer; //This is the time the current message has been processed. If several computers report a high value at the same time it indicates a freeze!
TotalTimeFrame: Integer; //This is the total time measured in microseconds
MessageCount: Integer;
TimeClasses: array [0..TimeClassMax] of Integer;
procedure CopyToBytes(var Buffer: TIdBytes);
end
Implementation of the CopyToBytes
procedure TTimeDataRecord.CopyToBytes(var Buffer: TIdBytes);
begin
// copy the data however you see fit
end;
Best Answer
Something like this