Solved

Setting DOS Environment Variables

Posted on 1997-03-25
2
180 Views
Last Modified: 2010-04-04
How do I set a DOS environment variable under Delphi 2.0.
I am currently using:-
      SetEnvironmentVariable('DFPATH', NewVarDirectory);

When I do I get an error Stating: "Incompatible Types 'String' and 'PCHAR'"
The variable NewVarDirectory simply holds the new directory name.

When I use
      SetEnvironmentVariable('DFPATH', 'F:\PRG\PROGRAMS');
there is no error generated.

Regards
Eric Kay
0
Comment
Question by:Eric Kay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
mheacock earned 100 total points
ID: 1334959
your variable NewVarDirectory is a variable of type string.
All Win API functions require null-terminated strings
or PChars.

You'll need to convert the string to a PChar before you use it.
Or, if you are using D@, you can typecast the string.

There are conversion functions...StrPCopy and StrPas that
will do the trick.  See the help files.

If you want to typecast, do the following:

   SetEnvironmentVariable('DFPATH', PChar(NewVarDirectory));

0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334960
D@ = Delphi 2

Forgot to let go of the shift key.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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