This code gives me an error message: [Error] Unit1.pas(52): Undeclared identifier: \'Edit1\'.
procedure SetTCPIPDNSAddresses(sIPs : String);
begin
If you cannot use the solution that Ken White gave you, for instance if you are not allowed to change the signature of SetTCPIPDNSAddresses(), then another option is to access the TEdit via the global pointer to its parent TForm (if your TForm instance is actually making use of that pointer, that is), eg:
procedure SetTCPIPDNSAddresses(sIPs : String);
begin
SaveStringToRegistry_LOCAL_MACHINE(
'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + Form1.Edit1.Text,
'NameServer', sIPs);
end;
Your code isn't a method of the form, and therefore has no access to Edit1.
Either make it a form method:
type
TForm1=class(TForm)
...
private
procedure SetTCPIPDNSAddresses(sIPs : String);
...
end;
implementation
procedure TForm1.SetTCPIPDNSAddresses(sIPs : String);
begin
...
end;
Or change it to accept the contents of Edit1.Text as another parameter:
procedure SetTCPIPDNSAddresses(sIPs : String; RegName: String);
begin
SaveStringToRegistry_LOCAL_MACHINE(
'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' +
RegName, 'NameServer', sIPs);
end;
And call it like:
SetTCPIPDNSAddresses(sTheIPs, Edit1.Text);