Why does the compiler say "Undeclared identifier" for my form's fields?

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?

Answers


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);

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; 

Need Your Help

Does Bluemix provide API to access MQA metrics

ibm-cloud ibm-mobile-services

I have integrated my mobile applications (android/ iOS) with bluemix MQA and we are able to view the metrics in the bluxmix dashboard/ console.

qt gui project in eclipse using qt plugin

c++ eclipse qt user-interface windows-7

So I have made a new qt gui project, gave it a name and right after it was created i received this error: