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
Solved

Setting DOS Environment Variables

Posted on 1997-03-25
2
176 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
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
how to center only a line in richedit? 4 61
Working with hours 3 65
RESTRequest Parameter 4 42
DBCtrlGrid, Delphi, Scroll 8 37
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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