Интернет-решения от доктора Боба


         

Переменные среды


Стандартное CGI приложение должно анализировать переменные среды для определения метода передачи и размера посылаемой информации через стандартный ввод. Для получения списка переменных среды я всегда использую простой компонент, который я написал очень давно и компилирую его с помощью директив условной компиляции, как в Дельфи 1, так и в Дельфи 2.

 unit TBDosEnv;

 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;

   protected

   { Protected method declarations }

     function GetDosEnvCount: Word;

   public

   { Public interface declarations }

     function GetDosEnvStr(Const Name: String): String;

     { This function is a modified version of the GetEnvVar function that

       appears in the WinDos unit that comes with Delphi. This function's

       interface uses Pascal strings instead of null-terminated strings.

     }

     property DosEnvCount: Word read GetDosEnvCount;

     property DosEnvList: TStringList read FDosEnvList;

   end;

 implementation

   constructor TBDosEnvironment.Create(AOwner: TComponent);

   var P: PChar;

       i: Integer;

   begin

     inherited Create(AOwner);

     FDosEnvList := TStringList.Create;

     {$IFDEF WIN32}

     P := GetEnvironmentStrings;

     {$ELSE}

     P := GetDosEnvironment; { Win API }

     {$ENDIF}

     i := 0;

     while P^ <> #0 do

     begin

       Inc(i);

       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};

   function




Содержание  Назад  Вперед