Интернет решения от доктора Боба | страница 14
чтобы вы могли иметь доступ до переменных среды DOS:
> unit DrBobDOS;
> interface
> uses
> SysUtils, WinTypes, WinProcs, Classes;
> type
> TBDosEnvironment = class(TComponent)
> public
> { Public class declarations (override) }
> constructor Create(AOwner: TComponent); override;
> destructor Destroy; override;
> private
> { Private field declarations }
> FDosEnvList: TStringList;
> procedure DoNothing(const Value: TStringList);
> protected
> { Protected method declarations }
> Dummy: Word;
> function GetDosEnvCount: Word;
> public
> { Public interface declarations }
> function GetDosEnvStr(const Name: String): String;
> { This function is a modified version of the GetEnvVar function thatappears in the WinDos unit that comes with Delphi. This function's interface uses Pascal strings instead of null-terminated strings.
> }
> published
> { Published design declarations }
> property DosEnvCount: Word read GetDosEnvCount write Dummy;
> property DosEnvList: TStringList read FDosEnvList write DoNothing;
> end;
> implementation
> constructor TBDosEnvironment.Create(AOwner: TComponent);
> var
> P: PChar;
> begin
> inherited Create(AOwner);
> FDosEnvList := TStringList.Create;
> {$IFDEF WIN32}
> P := GetEnvironmentStrings;
> {$ELSE}
> P := GetDosEnvironment;
> {$ENDIF}
> while P^ <> #0 do
> begin
> FDosEnvList.Add(StrPas(P));
> Inc(P, StrLen(P)+1) { Fast Jump to Next Var }
> end;
> end{Create};
> destructor TBDosEnvironment.Destroy;
> begin
> FDosEnvList.Free;
> FDosEnvList := nil;
> inherited Destroy
> end{Destroy};
> procedure TBDosEnvironment.DoNothing(const Value: StringList);
> begin
> end{DoNothing};
> function TBDosEnvironment.GetDosEnvCount: Word;
> begin
> if Assigned(FDosEnvList) then
> Result := FDosEnvList.Count
> else
> Result := 0;
> end{GetDosEnvCount};
> function TBDosEnvironment.GetDosEnvStr(const Name: String): String;
> var
> i: Integer;
> Tmp: String;
> begin
> i := 0;
> Result := '';
> if Assigned(FDosEnvList) then while i < FDosEnvList.Count do
> begin
> Tmp := FDosEnvList[i];
> Inc(i);
> if Pos(Name,Tmp) = 1 then
> begin
> Delete(Tmp,1,Length(Name));
> if Tmp[1] = '=' then
> begin
> Delete(Tmp,1,1);
> Result := Tmp;
> i := FDosEnvList.Count { end while-loop }
> end
> end
> end
> end{GetDosEnvStr};
> end.
Здесь список переменных среды (предоставленный Deepak Shenoy), которые доступны для CGI программ. Даже ISAPI программы могут использовать эти переменные: