The DataCAD Developer Network (DDN) is an online resource for information and support for DCAL® (DataCAD Applications Language) developers as well as anyone interested in creating fonts, toolbars, hatch patterns, or linetypes for use in DataCAD.

Moderator: pjdixit

#77131 by Joseph Baron
Thu Oct 24, 2019 4:48 pm
I have a need to use DCAL envget(), which seems simple enough, except I have not been able to get it to return any values.

Does anyone know the trick to get this to return environment values?

Thanks in advance!
#77143 by dhs
Fri Oct 25, 2019 3:48 pm
Hi Joseph,

Have just tried envget() myself and get the same result as you. Not particularly surprised by this.

As the DCAL function does not work my workaround would be to write a small Delphi program to get the variable and to call that program from the DCAL macro. Not a particularly elegant approach, but it can provide the required information. I have written a quick example of this which appears to work ok (although you may wish to implement some error checking etc if you choose to implement this approach).

My Delphi Code:
Code: Select allprogram EnvGet;



  env : string;
  envFile : TextFile;
   env := GetEnvironmentVariable (ParamStr(1));   // get env variable using first command line parameter
   AssignFile(envFile, 'Env.txt');
   WriteLn(envFile, env);     // write env variable value to Env.txt file

My code for a DCAL macro to call the above program:
Code: Select allPROGRAM GetEnv;

PROCEDURE execAndWait ( prog : str255; Visibility: integer; returnCode : OUT integer); BUILTIN 632;

    s : str255;
    i : integer;
    fl : file;

       WrtMsg ('Env Variable Name:');
       s :=  '';
       GetStr (s, 255);
       if strlen(s) > 0 then
           strins (s, 'EnvGet.exe ', 1);    ! s now has 'EnvGet.exe' followed by a space followed by
                                            ! env variable name  ... env variable is effectively the
                                            ! first command line parameter
           ExecAndWait (s, 0, i);    ! call EnvGet.exe
           i := f_open (fl, 'Env.txt', true, fmode_read);    ! EnvGet.exe writes result to Env.txt file, so
                                                             ! read that file to get result
           i := f_rdstr (fl, s);
           i := f_close (fl);
           WrtMsg ('Env Variable Value:');
           getstr (s, 255);
   UNTIL strlen (s) = 0;      ! keep processing until user leaves variable name blank
END GetEnv.

Have attached the compiled versions of the above for anybody that is interested.
(65.34 KiB) Downloaded 5 times
#77144 by Joseph Baron
Fri Oct 25, 2019 4:27 pm
Wow thank you very much David. It's time I start learning this D4D stuff, thank you so much for the help.
#77210 by dhs
Sat Nov 09, 2019 3:57 pm
Have made a couple of refinements to my Delphi envget program:

It will now accept a second parameter to specify the destination file (which could include a fully qualified path if required).
I'm a bit hesitant in recommending the use of this second parameter as I don't think the method of adding parameters using ExecAndWait will handle spaces very well (if at all), but it should handle file names without any spaces without problem.

The other refinement is to ensure that the Env.txt file is written to the same directory where the EnvGet.exe resides (in the event that parameter 2 is not specified).

Here is the source of the new version:
Code: Select allprogram EnvGet;



  env : string;
  envFile : TextFile;
  envFileName : string;
   env := GetEnvironmentVariable (ParamStr(1));   // get env variable using first command line parameter
   if length (ParamStr(2)) > 0 then
     envFileName := ParamStr(2)      // use param 2 as output file if it exists
    envFileName := ExtractFilePath(ParamStr(0)) + 'Env.txt';      // write env.txt to thefile path of exe
   AssignFile (envFile, envFileName);
   WriteLn(envFile, env);     // write env variable value to output file

Compiled version is attached. You are free to use this if you wish (as with all my offerings there is absolutely no obligation but a contribution towards cost of development would be appreciated if you find it useful)
(70.3 KiB) Not downloaded yet

Who is online

Users browsing this forum: No registered users and 0 guests

About DataCAD Forum

The DataCAD Forum is a FREE online community we provide to enhance your experience with DataCAD.

We hope you'll visit often to get answers, share ideas, and interact with other DataCAD users around the world.


Software for AEC Professionals Since 1984