// Take getwindowsdirectory as an example: {buffer using static arrays} procedure tform1.button1click (Sender: tobject); var Buf: array [0 .. MAX_PATH-1] of char; begin getwindowsdirectory (BUF, sizeof (BUF); showmessage (BUF); {C: \ WINDOWS} end; {self-allocated memory} procedure tform1.button2click (Sender: tobject); var P: pchar; begin P: = stralloc (max_path); getwindowsdirectory (p, strbufsize (p); showmessage (p); {C: \ Windows} strdispose (p); end; {use string directly; this and the following methods both need to delete the trailing Blank} procedure tform1.button3click (Sender: tobject); var STR: string; len: integer; begin setlength (STR, max_path); Len: = getwindowsdirectory (pchar (STR), bytelength (STR); setlength (STR, Len); showmessage (STR ); {C: \ Windows} end; {change pchar (STR) to @ STR [1]} procedure tform1.button4click (Sender: tobject); var STR: string; Len: integer; begin setlength (STR, max_path); Len: = getwindowsdirectory (@ STR [1], bytelength (STR); setlength (STR, Len); showmessage (STR ); {C: \ Windows} end; {This method is the best. Obtain the result length first ...} procedure tform1.button5click (Sender: tobject); var Len: integer; STR: string; begin Len: = getwindowsdirectory (nil, 0); setlength (STR, Len ); getwindowsdirectory (pchar (STR), Len); showmessage (STR); {C :\\ windows} end;