[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

String and pChar

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
omsec
Asked:
omsec
1 Solution
 
BlackManCommented:
Use StrPCopy (see helpfile for documentation)
0
 
ronit051397Commented:
or use TypeCasting:

var A: pChar;
     B: String;
begin
  B:='Example';
  A:=pChar(B);
end;
0
 
rickpetCommented:
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

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now