⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dosenv01.pas

📁 Controled counter delphi
💻 PAS
字号:
unit DosEnv01;
{ Class to read the DOS Environment variables }

interface

uses SysUtils, WinProcs, Classes;

type
  TDOSEnvironment = class
  private
    FKeys: TStringList;
    FValues: TStringList;
    function GetCount: Integer;
    function GetKey(Index: Integer): string;
    function GetValue(Index: Integer): string;
  protected
  public
    constructor Create;
    destructor Destroy; override;
    function ValueForKey(const Key: string): string;
    property Count: Integer read GetCount;
    property Key[Index: Integer]: string read GetKey;
    property Value[Index: Integer]: string read GetValue;
  end;

implementation

{ TDOSEnvironment }

constructor TDOSEnvironment.Create;
var
  EnvStrings: PChar;
  S: string;

begin
  FKeys := TStringList.Create;
  FValues := TStringList.Create;

  {$IFDEF WIN32}
    EnvStrings := GetEnvironmentStrings;
  {$ELSE}
    EnvStrings := GetDosEnvironment;
  {$ENDIF}

  while EnvStrings[0] <> #0 do
    begin
      S := StrPas(EnvStrings);
      FKeys.Add(Copy(S,1,Pos('=',S)-1));
      FValues.Add(Copy(S,Pos('=',S)+1,255));
      Inc(EnvStrings,StrLen(EnvStrings)+1);
    end;
end;

destructor TDOSEnvironment.Destroy;
begin
  FKeys.Free;
  FValues.Free;
end;

function TDOSEnvironment.ValueForKey(const Key: string): string;
var
  I: Integer;

begin
  I := FKeys.IndexOf(Key);
  if I >= 0 then
    Result := FValues.Strings[I]
  else
    Result := '';
end;

function TDOSEnvironment.GetCount: Integer;
begin
  Result := FKeys.Count;
end;

function TDOSEnvironment.GetKey(Index: Integer): string;
begin
  Result := FKeys.Strings[Index];
end;

function TDOSEnvironment.GetValue(Index: Integer): string;
begin
  Result := FValues.Strings[Index];
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -