此代码给出了一条错误消息:[Error] Unit1.pas(52):未声明的标识符:’Edit1′.
procedure SetTCPIPDNSAddresses(sIPs : String); begin SaveStringToRegistry_LOCAL_MACHINE( 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + Edit1.text,'NameServer',sIPs); end;
解决方法@H_502_8@
您的代码不是表单的方法,因此无法访问Edit1.
要么使它成为一种形式方法:
type
TForm1=class(TForm)
...
private
procedure SetTCPIPDNSAddresses(sIPs : String);
...
end;
implementation
procedure TForm1.SetTCPIPDNSAddresses(sIPs : String);
begin
...
end;
或者将其更改为接受Edit1.Text的内容作为另一个参数:
procedure SetTCPIPDNSAddresses(sIPs : String; RegName: String);
begin
SaveStringToRegistry_LOCAL_MACHINE(
'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' +
RegName,sIPs);
end;
称之为:
SetTCPIPDNSAddresses(sTheIPs,Edit1.Text);
要么使它成为一种形式方法:
type TForm1=class(TForm) ... private procedure SetTCPIPDNSAddresses(sIPs : String); ... end; implementation procedure TForm1.SetTCPIPDNSAddresses(sIPs : String); begin ... end;
或者将其更改为接受Edit1.Text的内容作为另一个参数:
procedure SetTCPIPDNSAddresses(sIPs : String; RegName: String); begin SaveStringToRegistry_LOCAL_MACHINE( 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + RegName,sIPs); end;
称之为:
SetTCPIPDNSAddresses(sTheIPs,Edit1.Text);