delphi InternetQueryOption 可用demo
时间: 2024-09-09 15:17:24 浏览: 60
在 Delphi 7 中,`InternetQueryOption` 函数通常用于访问系统网络设置,比如代理服务器信息。下面是一个简单的示例演示如何获取代理服务器的信息:
```delphi
unit Unit1;
interface
uses
Windows, Classes, Internet;
type
TInternetOptionStruct = packed record
fdwOption: DWORD;
lpszBuffer: ^TCHAR;
dwBufferLength: DWORD;
dwOptionsLength: DWORD;
end;
TProxyOptionStruct = packed record
szProxy: array[0..MAX_PATH] of Char;
dwPort: DWORD;
end;
TProxyBypassListStruct = packed record
cEntries: DWORD;
aEntry: array[0..MAX_PATH - 1] of Char;
end;
var
ProxySettings: TInternetOptionStruct;
implementation
procedure GetProxySettings;
var
ProxyServer: string;
begin
ProxySettings.fdwOption := INTERNET_OPTION_PROXY;
ProxySettings.lpszBuffer := @ProxyServer;
ProxySettings.dwBufferLength := MaxAnsiStrLen('Default') + 1; // 预留空间
ProxySettings.dwOptionsLength := SizeOf(TProxyOptionStruct);
if not InternetQueryOption(0, ProxySettings, @ProxySettings.dwBufferLength, True) then
begin
ShowMessage('Failed to get proxy settings.');
Exit;
end;
// 解析 ProxyServer 字符串,例如 "192.168.1.1:8080"
Writeln('Proxy Server: ', ProxyServer);
end;
begin
Application.Initialize;
Application.MainForm.OnCreate := FormCreate;
Application.Run;
end.
procedure TForm1.FormCreate(Sender: TObject);
begin
GetProxySettings;
end.