I'm using Delphi XE2, is there a command in Delphi equivalent to pack() in PHP? I need to convert a Delphi record containing integers and strings into to binary, for transmitting over TCP.
Asked
Active
Viewed 578 times
0
-
If you really just have a string, you don't need `pack`; you can just sent the string as-is. You'd only need `pack` if you had lots of values to send in a single unit. There's no built-in function for that, but it wouldn't be hard to write. (But `unpack` could be tricky, if you need that, too.) – Rob Kennedy Aug 07 '12 at 15:31
-
Thanks, sorry should have been more clear - it is a set of mixed data values I need to send in a single unit. – Jonathan Wareham Aug 07 '12 at 15:35
-
1@JonathanWareham: Is it a record? If so, does it contain variable-length or fixed-length string types? You should give the precise details, because they matter. – Andreas Rejbrand Aug 07 '12 at 15:38
-
Hi Andreas, it is a record and consists of integers, a fixed length string and a variable length string. – Jonathan Wareham Aug 07 '12 at 15:48
-
Actually `pack()` returns a string. – David Heffernan Aug 07 '12 at 16:11
-
https://www.google.ru/search?q=delphi+serialization&sourceid=opera&client=opera&ie=utf-8&oe=utf-8&channel=suggest http://code.google.com/p/superobject/wiki/first_steps http://stackoverflow.com/questions/3750072 http://stackoverflow.com/search?q=serialize+delphi&submit=search – Arioch 'The Aug 08 '12 at 05:57
1 Answers
0
There is no built in method that will convert a generic record into binary form (or vice versa). You will need to either:
- Write your own dedicated code to do so, or
- Find and use an object persistence library.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490