I’m writing a wrapper for communication with an external binary API. The API uses PDUs (packed binary records) for communication. Strings are arrays of AnsiChar and are zero-terminated:
type
TSomePDU = packed record
//...
StringField: array[0..XYZ] of AnsiChar;
//...
end;
PSomePDU = ^TSomePDU;
I want to write a FillPDUString procedure that would accept a String and fill the char array, but I want to avoid keeping track of MaxLength wherever the procedure is used, so I need somehow to get the declared array size given a pointer to the field:
function GetMaxSize(const Field: array of AnsiChar): Integer;
begin
// ???
end;
//...
GetMaxSize(ARecord.StringField);
Is this possible?
If I understand you correctly, then you can use Delphi’s Length function
Here’s how to get the length: