🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.delphi.misc
Article #568

Re: HELP : GetPrivateProfileString ??????

#568
From: David Rifkind
Date: Sun, 02 May 1999 00:00
41 lines
2479 bytes
On Sat, 01 May 1999 21:38:44 +0800, Chow <d951686@sftw.umac.mo> wrote:
>Hello,
>
>What's wrong with the following Code ???
>
>Var
>iPath : PChar;
>.......
>
>iPath := PChar(ExtractFilePath(Application.ExeName) + 'test.ini');
>GetPrivateProfile('Option', 'KeyA', ' ', xStr, 80, iPath);
>....
>
>This can return the right string if I run it in Delphi IDE.
>But it can't get anything when I use Dos-Prompt or in Windows's RUN.

I don't know if this is the source of your trouble (it seems unlikely)
but...

>iPath := PChar(ExtractFilePath(Application.ExeName) + 'test.ini');

When an expression returns a string, it returns it as a temporary value.
You can cast that value to a PChar, but you have no guarantee as to how
long it will remain valid.  To be sure, you have two options.  You can
store the value in a string variable, and cast *that* to PChar...

  sPath := ExtractFilePath(Application.ExeName) + 'test.ini';
  iPath := PChar(sPath);
  GetPrivateProfile('Option', 'KeyA', ' ', xStr, 80, iPath);

...or you can evaluate the expression in-line...

  GetPrivateProfile('Option', 'KeyA', ' ', xStr, 80,
    PChar(ExtractFilePath(Application.ExeName) + 'test.ini'));

...since temporary strings created while evaluating a statement are not
freed until the end of that statement.

-- 
"Oh, shootings.  Yes, but that doesn't mean Americans are more violent
than other people.  We're just better shots."
Technical Details
Message-ID: <372cefd9.14278841@netnews.worldnet.att.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <372B03E4.C14208BB@sftw.umac.mo>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1091e5,d793697369ac48cf
X-Google-Attributes: gid1091e5,public
X-Google-Thread: 1043cf,d793697369ac48cf
X-Google-Attributes: gid1043cf,public
X-Google-Thread: fd817,d793697369ac48cf
X-Google-Attributes: gidfd817,public
X-Google-Thread: 10baee,d793697369ac48cf
X-Google-Attributes: gid10baee,public
From: drifkind@acm.deleteme.org (David Rifkind)
Subject: Re: HELP : GetPrivateProfileString ??????
Date: 1999/05/02
Message-ID: <372cefd9.14278841@netnews.worldnet.att.net>
X-Deja-AN: 473095882
Content-Transfer-Encoding: 7bit
References: <372B03E4.C14208BB@sftw.umac.mo>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@worldnet.att.net
X-Trace: bgtnsc03.worldnet.att.net 925626731 22610 12.64.38.28 (2 May 1999 06:32:11 GMT)
Organization: ()
Mime-Version: 1.0
NNTP-Posting-Date: 2 May 1999 06:32:11 GMT
Newsgroups: comp.lang.pascal.delphi.misc,alt.comp.lang.borland-delphi,borland.public.delphi.objectpascal,borland.public.delphi.winapi