【例子介绍】 Delphi读取Windows环境参数信息.
【相关图片】
【源码结构】
unit getUSERDNSDOMAIN; interface {uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; } uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, WinSock, BtnListB, NB30, StrUtils, CryptUnit, OleCtrls, SHDocVw, ExtCtrls, DB, DBClient, uRODataSnapConnection, uROClient, uROWinInetHttpChannel, Grids, DBGrids, ImgList, uROBinMessage ; type TForm1 = class(TForm) ListBox1: TListBox; Panel1: TPanel; Button2: TButton; Button1: TButton; Edit1: TEdit; function ReadCupSet(setcmd: String): String; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public function PathGetSystemPath: string; { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function TForm1.PathGetSystemPath: string; var Buf: array[0..255] of Char; begin GetWindowsDirectory(@Buf, 255); Result := Buf; end; procedure TForm1.Button1Click(Sender: TObject); begin edit1.text := PathGetSystemPath(); end; procedure TForm1.Button2Click(Sender: TObject); begin edit1.text := ReadCupSet('USERDOMAIN'); end; function TForm1.ReadCupSet(setcmd: String): String; VAR EnvPtr, SavePtr: PChar; str, RE: string; begin RE := 'no'; EnvPtr := GetEnvironmentStrings; SavePtr := EnvPtr; //保存GetEnvironmentStrings的返回值,以后要调用FreeEnvironmentStrings来释放内存。 repeat str := StrPas(EnvPtr); if AnsiStartsText(setcmd, STR) then BEGIN RE := rightstr(str, Length(str) - Length(setcmd) - 1); END; ListBox1.Items.Add(str); inc(EnvPtr, StrLen(EnvPtr) 1); until EnvPtr^ = #0; FreeEnvironmentStrings(SavePtr); RESULT := RE; end; end.
评论