emurad
emurad

Reputation: 3578

Why does the compiler say "undeclared identifier" when I try to show form B from form A?

Why this code is not working:

procedure TFormNotification.Button3Click(Sender: TObject);
begin
  FormB.Show;
end;

I'm getting Undeclared identifier error.

Upvotes: 3

Views: 19092

Answers (2)

David Heffernan
David Heffernan

Reputation: 613541

You need to add the unit in which FormB is declared to your uses clause.

Upvotes: 5

Rob Kennedy
Rob Kennedy

Reputation: 163357

You probably have a global variable named FormB declared in the interface section of a unit named UnitB. But UnitA doesn't know anything about that unit or its contents. In particular, it doesn't know what the word FormB means — that identifier is undeclared.

To tell UnitA about the things declared in UnitB, add UnitB to the uses clause in UnitA:

uses Windows, SysUtils, Forms, Classes, UnitB;

Upvotes: 11

Related Questions