We help IT Professionals succeed at work.

String and pChar

omsec
omsec asked
on
Medium Priority
442 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 :)
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
or use TypeCasting:

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

Commented:
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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.