开发者

Pointer to String conversion?

I am allocating the memory with GetMem (1028 bytes length), so I have an allocated Pointer.

Then I am reading the co开发者_如何学编程ntent and I know that there is e.g. 1028 bytes read. how can I cast pointer, or convert it to a string?

Should I null terminate the content of the memory prior to conversion?

Thanks!


Use SetString. Pass it a string variable, your pointer, and the string length (1028). Delphi strings are implicitly null-terminated, so the function will add that automatically (even if your buffer already has null bytes in it).

Better yet, set the length of the string and read your data directly into it instead of using an intermediary buffer. If you must use an intermediary buffer, you may as well use one that's statically sized to 1028 bytes instead of complicating your program with dynamic memory management.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜