Often the "Undeclared identifier" error is because you have made reference to a component/object without including the necessary file in the "uses" clause. So immediately you get the error look for the component/object it highlights in the help file (as you found out and as Kistal pointed out).
Just another thing to note: you may come across the
uses clause in two places - the
interface section and the
implementation section. Basically if the unit you want to include (in the
uses clause) is needed in order to declare something in the
interface part then place it in the
interface section's
uses clause. If, however, the unit to be included is only needed in your main code (
implementation section) and not in the declarations (
interface section) then declare it in the
implementation section's uses clause.
Here's an example: if you wanted to use the
function to calculate the hypotenuse given two numbers as input, you would only be using it in the implementation of your code so you would place the
Math unit in your
implementation uses clause.
Code:
unit HypotExample;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Math;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
hypotenuseValue: Extended;
begin
hypotenuseValue := Hypot(StrToInt(Edit1.Text), StrToInt(Edit2.Text));
Label1.Caption := FloatToStr(hypotenuseValue);
end;
end.
Marco Cantu has a tip on this in his book "Mastering Delphi 6":
"When you need to refer to another unit of a program, place the corresponding uses statement in the implementation portion instead of the interface portion if possible. This speeds up the compilation process, results in cleaner code (because the units you include are separate from those included by Delphi), and prevents circular unit compilation errors. To accomplish this, you can also use the File->Use Unit menu command." (p327) Clive
Ex nihilo, nihil fit (Out of nothing, nothing comes)