Conversion between Delphi string, Pchar, and character array

Source: Internet
Author: User
Conversion between Delphi string, Pchar, and character array

Conversion between Delphi string, Pchar, and character array
The following three variables are available:
Var
s:string;
P:pchar;
A:ARRAY[1..20] of Char;
Then the conversion between the three is as follows:
1. String to Pchar
P:=pchar (s);
2, Pchar to String
S:=p;
3, Pchar to character array
Strcopy (@a, p);
4, character array to Pchar
PChar (@a);
5, the conversion between the string and the character array can only be brokered by Pchar. For example, the following example:
Procedure Tform1.btn1click (Sender:tobject);
Var
STR:ARRAY[1..10] of Char;
Begin
Strcopy (@str, PChar (mmo1. Text));
Mmo2. Text:=pchar (@str);
End


Conversion between Delphi string, Pchar, and character array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.