Reputation: 101
This code gives me an error message: [Error] Unit1.pas(52): Undeclared identifier: 'Edit1'.
procedure SetTCPIPDNSAddresses(sIPs : String);
begin
SaveStringToRegistry_LOCAL_MACHINE(
'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + Edit1.text,
'NameServer', sIPs);
end;
Why do I get this error, and how do I fix it?
Upvotes: 0
Views: 3452
Reputation: 598279
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;
Upvotes: 0
Reputation: 125757
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);
Upvotes: 7