Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

delphi - 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(
    'SYSTEMCurrentControlSetServicesTcpipParametersInterfaces' + Edit1.text,
    'NameServer', sIPs);
end;

Why do I get this error, and how do I fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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(
    'SYSTEMCurrentControlSetServicesTcpipParametersInterfaces' + 
     RegName, 'NameServer', sIPs);
end;

And call it like:

SetTCPIPDNSAddresses(sTheIPs, Edit1.Text);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...