Code
Procedure createenvironment (const alibpath, aincpath: string );
Resourcestring
Reg_c51_lib = 'c51lib ';
Reg_c51_inc = 'c51inc ';
Reg_path = 'path ';
Reg_machine_location = 'System \ CurrentControlSet \ Control \ Session Manager \ environment ';
Reg_user_location = 'enable ';
VaR
Fpath: string;
Function dataexits (const asources, aData: string): Boolean;
VaR
Flist: tstrings;
I: integer;
Begin
Result: = false;
Flist: = Split (asources ,';');
For I: = 0 to flist. Count-1 do
Begin
If flist [I] = aData then result: = true;
End;
End;
Begin
With Tregistry. Create do
Begin
Try
Rootkey: = HKEY_LOCAL_MACHINE;
Openkey (reg_machine_location, true );
Fpath: = readstring (reg_path );
If not dataexits (fpath, alibpath) then
Begin
Fpath: = readstring (reg_path) + alibpath + ';';
Writestring (reg_path, fpath );
Setenvironmentvariable (pchar (reg_c51_lib), pchar (alibpath ));
// Sendmessage (hwnd_broadcast, wm_settingchange, 0, INTEGER (pchar ('Environment ')));
End;
Fpath: = readstring (reg_path );
If not dataexits (fpath, aincpath) then
Begin
Fpath: = readstring (reg_path) + aincpath + ';';
Writestring (reg_path, fpath );
Setenvironmentvariable (pchar (reg_c51_lib), pchar (alibpath ));
// Sendmessage (hwnd_broadcast, wm_settingchange, 0, INTEGER (pchar ('Environment ')));
End;
Sendmessage (hwnd_broadcast, wm_settingchange, 0, INTEGER (pchar ('Environment ')));
Finally
Free;
End;
End;
End;