Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DELPHI: how to convert pChar to string ?

6,085 views
Skip to first unread message

Travis Metcalf

unread,
Apr 17, 1995, 3:00:00 AM4/17/95
to
I am wondering how to convert a pChar to a string.

I am using a pChar variable to get string infromation from
GetPrivateProfileString, and I would like to put this information
into a string variable. What should I do?

travis
tmet...@teleport.com


vict...@delphi.com

unread,
Apr 17, 1995, 3:00:00 AM4/17/95
to
Travis Metcalf <tmet...@teleport.com> writes:

>I am wondering how to convert a pChar to a string.

{StrPas.PAS}

{Sample code for the StrPas function.}

uses SysUtils;

const
A: PChar = 'I love the smell of ObjectPascal in the morning.';
var
S: String[79];
begin
S := StrPas(A);
Canvas.TextOut(10, 10, S);
end.


This come from the Delphi Help File if you search for StrPas.

--Victor J. DuLuc

Anders Ohlsson

unread,
Apr 18, 1995, 3:00:00 AM4/18/95
to
In article <3mujpl$f...@sandra.teleport.com> tmet...@teleport.com (Travis Metcalf) writes:
>I am wondering how to convert a pChar to a string.

Check the online help for string manipulation routines. I think you're
after something like StrPas/StrPCopy.

>I am using a pChar variable to get string infromation from
>GetPrivateProfileString, and I would like to put this information
>into a string variable. What should I do?

Abandon GetPrivateProfileString and take a look at the IniFiles unit
instead. Check out the online docs on the TIniFile type.

/Anders

-----------------------------------------------------------------------------
! The Windoze program you want is at http://www.it.kth.se/~ao/yacpu20.zip !
! !
! Anders Ohlsson - a...@sto.foa.se - http://www.it.kth.se/~ao !
-----------------------------------------------------------------------------

Conor Cagney

unread,
Apr 18, 1995, 3:00:00 AM4/18/95
to
In article <3mujpl$f...@sandra.teleport.com>,

tmet...@teleport.com (Travis Metcalf) wrote:
>I am wondering how to convert a pChar to a string.
>
>I am using a pChar variable to get string infromation from
>GetPrivateProfileString, and I would like to put this information
>into a string variable. What should I do?
>
>travis
>tmet...@teleport.com
>
var
MyString: string;
MyPChar: PChar;
begin
{allocate and fill your PChar}

MyString := StrPas(MyPChar);

{deallocate the PChar}
end;

But you might try and use TIniFile type.....it worked for me (except
for a *slight* bug in WriteBool(..)!)

Regards
Conor Cagney

Marc Morant

unread,
Apr 20, 1995, 3:00:00 AM4/20/95
to
tmet...@teleport.com said that...

>
>I am wondering how to convert a pChar to a string.
>
>I am using a pChar variable to get string infromation from
>GetPrivateProfileString, and I would like to put this information
>into a string variable. What should I do?

Look up StrToPas in the Help Section.

All the best
Marc


Marc Morant

unread,
Apr 20, 1995, 3:00:00 AM4/20/95
to
mmo...@werple.mira.net.au said that...

>
>tmet...@teleport.com said that...
>>
>>I am wondering how to convert a pChar to a string.
>>
>>I am using a pChar variable to get string infromation from
>>GetPrivateProfileString, and I would like to put this information
>>into a string variable. What should I do?
>
Oops I blundered when I said....

>Look up StrToPas in the Help Section.
EEEKKKK It's StrPas *NOT* StrToPas

What was I thinking.

BTW a trick way Pascal to Str type:

var
AString: String;
AStr: PChar;
begin
AString:='This is a normal Pascal String'+#0;
AStr:=@AString[1];
WritePrivateProfileString(.....@Astring[1]....);
end;

Why?

A pascal String is layed out with the length of the string in
character[0] with the actual characters starting at character[1]

This also means than Ord(AString[1]) gives you the length!

A C string is a pointer (Hence the @) to the first character of
a string (Hence AString[1]). No length is encoded, the string is
variable length and stops at a null character (Ascii 0 or ASCIIZ)
hence the #0!

All the best
Marc


0 new messages