Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

String and pChar

Posted on 1998-06-03
3
Medium Priority
?
417 Views
Last Modified: 2010-08-05
I should assign a String-Value to a pChar-Variable. But the Compiler (Delphi 3 Prof) sais, 'incompatible types'. So is there any way to convert a String into a pChar ? I should use that, because the origin of the data, the String is stored in a binary file, more exactly in an array of string in that file. I used string, becuz it seems, the program couldn't read the pChar-Value exactly when I wrote ArrayName[IndexVar] (I got only a part of the data back).

I cannot change what the function expects, it wants a pChar, so best way will probly be to do a convert from String to pChar, but how ?

thanx :)
0
Comment
Question by:omsec
3 Comments
 
LVL 7

Accepted Solution

by:
BlackMan earned 150 total points
ID: 1350018
Use StrPCopy (see helpfile for documentation)
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1350019
or use TypeCasting:

var A: pChar;
     B: String;
begin
  B:='Example';
  A:=pChar(B);
end;
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1350020
Also if you know the length that will be returned in the pchar use SetLength(myString,newlength) to set the length of the string;

Rick
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question