Home > Back-end > Sorry to ask a very basic question, I have been used, pchar how to do?
Sorry to ask a very basic question, I have been used, pchar how to do?
Time:09-18
Procedure TForm2. Button10Click (Sender: TObject); Var C, c1: PChar; The begin GetMem (c, 5); C1:='11.2'; Move (c1, c, 4); ShowMessage (c); FreeMem (c); end;
Why does the code freemem error? If I applied for memory for pchar variables, how to write the content in it? If don't have to getmem to also can be used directly as if c1, copies the contents of c1 to c in the move, why freemem error?
CodePudding user response:
http://blog.csdn.net/tjb_1216/article/details/4627346 Procedure TForm1. Button1Click (Sender: TObject); Var C, c1: PChar; The begin GetMem (c, 5); FillChar (c ^, # 5, 0). C1:='11.2'; Move (c1 ^, c ^ 4); ShowMessage (c); FreeMem (c); end;