ls_username:pchar;
ls_username:=StrAlloc(1024);谁能告诉我关于StrAlloc函数的具体用法和功能
我只知道StrAlloc是分配内存地址的
像上面那句话的具体意思是什么

解决方案 »

  1.   

    StrAlloc allocates a buffer for a null-terminated string with a maximum length of Size - 1 (1 byte must be reserved for the termination character). The result points to the location where the first character of the string is to be stored. A 32-bit number giving the total amount of memory allocated is stored in the four bytes preceding the first character; it is equal to Size + 4. If space for a string is allocated with StrAlloc, it should be deallocated via StrDispose.Because AnsiStrings (long strings) are implicitly null terminated and dynamically allocated, the use of StrAlloc is deprecated.StrAlloc可以分配最大为Size-1字节的空结束字符串(为什么不是Size?因为有一个字节用于存放结束符,即NULL)。函数的返回值指向已分配的字符串首个字符的地址。而在首字符的前面有4个字节的空间,存储着一个32位的值,该值等字符串分配的总内存大小,即等于Size+4。
    如果使用StrAlloc分配了字符串,则最后必须用StrDispose释放分配的内存,满足了吧。来自Delphi的帮助,按F1就可以了。