Q&A

  • PChar 과 String의 서로의 변환 어떻게 한가요?
안녕하셔요..영원한 델초보 어린왕자입니다..

제목 그대로 인데요...-.-;



PChar이란게 뭔가요?

PChar(String) 하면 String ---> PChar 맞죠?

PChar을 String으로 바꿀려면요???

1  COMMENTS
  • Profile
    bean 2001.05.19 01:27
    델 성경중 발췌했슴다.



    You can mix long strings (AnsiString values) and null-terminated strings (PChar values) in expressions and assignments, and you can pass PChar values to functions or procedures that take long-string parameters. The assignment S := P, where S is a string variable and P is a PChar expression, copies a null-terminated string into a long string.

    In a binary operation, if one operand is a long string and the other a PChar, the PChar operand is converted to a long string.



    You can cast a PChar value as a long string. This is useful when you want to perform a string operation on two PChar values. For example,



    S := string(P1) + string(P2); <<<<<<<<<<<<<<<<<<<<<<<<<<<< 요기



    You can also cast a long string as a null-terminated string. The following rules apply.



    If S is a long-string expression, PChar(S) casts S as a null-terminated string; it returns a pointer to the first character in S. For example, if Str1 and Str2 are long strings, you could call the Win32 API MessageBox function like this:



    MessageBox(0, PChar(Str1), PChar(Str2), MB_OK);



    (MessageBox is declared in the Windows interface unit.)



    You can also use Pointer(S) to cast a long string to an untyped pointer. But if S is empty, the typecast returns nil.

    When you cast a long-string variable to a pointer, the pointer remains valid until the variable is assigned a new value or goes out of scope. If you cast any other long-string expression to a pointer, the pointer is valid only within the statement where the typecast is performed.

    When you cast a long-string expression to a pointer, the pointer should usually be considered read-only. You can safely use the pointer to modify the long string only when all of the following conditions are satisfied.



    The expression cast is a long-string variable.

    The string is not empty.

    The string is unique