Discussion:
Undeclared identifier error getting.
(too old to reply)
Sandeepan Kashyap
2014-09-30 07:15:08 UTC
Permalink
Hi,

we are trying to access a function DoSomething() of unit stringcheck from unit Demographics . While running, we are getting 'Undeclared identifier: 'TSharedFunctions1' error, not sure why? though we have used the unit in main Unit.
Any ideas will be greatly appreciated.

unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils;
type
TSharedFunctions1 = class
public
function DoSomething: string;
end;
function TSharedFunctions1.DoSomething: string;
begin
Result := 'Something done';
end;
end.
*************************************************************************
Main Unit (Demographics;)
unit Demographics;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Final, stringcheck; //uses stringcheck.pas
type
TForm2 = class(TForm)
Name: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FinalVal(Sender: TObject);
private
{ Private declarations }
public
SharedData: TForm1;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FinalVal(Sender: TObject);
begin
ShowMessage('tetss'+ IntToStr(Form1.Test1));
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
ShowMessage('tetss print-'+ TSharedFunctions1.DoSomething()); //Undeclared identifier: 'TSharedFunctions1'
end;


Thanks
Sandeepan.
JJ
2014-09-30 09:31:04 UTC
Permalink
Post by Sandeepan Kashyap
Hi,
we are trying to access a function DoSomething() of unit stringcheck from unit Demographics . While running, we are getting 'Undeclared identifier: 'TSharedFunctions1' error, not sure why? though we have used the unit in main Unit.
Any ideas will be greatly appreciated.
unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils;
type
TSharedFunctions1 = class
public
function DoSomething: string;
end;
function TSharedFunctions1.DoSomething: string;
begin
Result := 'Something done';
end;
end.
[snip]

All global types and variables that are declared within *implementation*
block are private. Move them into the *interface* block.
Hans-Peter Diettrich
2014-09-30 09:23:55 UTC
Permalink
Post by Sandeepan Kashyap
Hi,
we are trying to access a function DoSomething() of unit stringcheck from unit Demographics . While running, we are getting 'Undeclared identifier: 'TSharedFunctions1' error, not sure why? though we have used the unit in main Unit.
Any ideas will be greatly appreciated.
unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils;
type
TSharedFunctions1 = class
Whatever shall be visible in other units must reside between "interface"
and "implementation". Just like in Demographics...

DoDi
Sandeepan Kashyap
2014-09-30 10:26:09 UTC
Permalink
Thanks JJ and DoDi for your valuable inputs.I tried as suggested, but still no success.

unit stringcheck;
interface
implementation
{$R *.RES}

uses sysutils ,StrUtils, Demographics;
type
TSharedFunctions1 = class
private
{ Private declarations }
public
function DoSomething: string;
end;
var
......
Post by Hans-Peter Diettrich
Post by Sandeepan Kashyap
Hi,
we are trying to access a function DoSomething() of unit stringcheck from unit Demographics . While running, we are getting 'Undeclared identifier: 'TSharedFunctions1' error, not sure why? though we have used the unit in main Unit.
Any ideas will be greatly appreciated.
unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils;
type
TSharedFunctions1 = class
Whatever shall be visible in other units must reside between "interface"
and "implementation". Just like in Demographics...
DoDi
Sandeepan Kashyap
2014-09-30 11:23:29 UTC
Permalink
Post by Sandeepan Kashyap
Thanks JJ and DoDi for your valuable inputs.I tried as suggested, but still no success.
unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils, Demographics;
type
TSharedFunctions1 = class
private
{ Private declarations }
public
function DoSomething: string;
end;
var
......
Post by Hans-Peter Diettrich
Post by Sandeepan Kashyap
Hi,
we are trying to access a function DoSomething() of unit stringcheck from unit Demographics . While running, we are getting 'Undeclared identifier: 'TSharedFunctions1' error, not sure why? though we have used the unit in main Unit.
Any ideas will be greatly appreciated.
unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils;
type
TSharedFunctions1 = class
Whatever shall be visible in other units must reside between "interface"
and "implementation". Just like in Demographics...
DoDi
Ok, I tried below, past error has gone, but now I am getting error in Demographics form (main form):
[Error] Demographics.pas(50): This form of method call only allowed for class methods


unit stringcheck;
interface
type
TSharedFunctions1 = class
private
{ Private declarations }
public
function DoSomething: string;
end;
implementation
{$R *.RES}
uses sysutils ,StrUtils;
_____________
Demographics form (main form):

procedure TForm2.Button1Click(Sender: TObject);
begin
ShowMessage('tetss-'+ TSharedFunctions1.DoSomething()); //getting error This form of method call only allowed for class methods
end;
Hans-Peter Diettrich
2014-09-30 14:31:42 UTC
Permalink
Post by Sandeepan Kashyap
Post by Sandeepan Kashyap
we are trying to access a function DoSomething() of unit stringcheck from unit Demographics . While running, we are getting 'Undeclared identifier: 'TSharedFunctions1' error, not sure why? though we have used the unit in main Unit.
[Error] Demographics.pas(50): This form of method call only allowed for class methods
procedure TForm2.Button1Click(Sender: TObject);
begin
ShowMessage('tetss-'+ TSharedFunctions1.DoSomething()); //getting error This form of method call only allowed for class methods
end;
You need an object before you can call one of its methods. E.g. add to
your form class
MyFuncs: TSharedFunctions;
and create it in e.g. FormCreate:
MyFuncs := TSharedFunctions1.Create;
Then use that object to call e.g. MyFuncs.DoSomething().

Or you forget about TSharedFunctions1 and make DoSomething a simple
function.

DoDi
Alan Lloyd
2014-10-05 18:26:21 UTC
Permalink
Sandeepan

Look up & understand a paragraph or section entitled "Scope" in the help
file you have for whatever version of Delphi you have. It explains all this
stuff that you're having problems with.

Alan Lloyd
Post by Sandeepan Kashyap
Hi,
we are trying to access a function DoSomething() of unit stringcheck from
'TSharedFunctions1' error, not sure why? though we have used the unit in
main Unit.
Any ideas will be greatly appreciated.
unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils;
type
TSharedFunctions1 = class
public
function DoSomething: string;
end;
function TSharedFunctions1.DoSomething: string;
begin
Result := 'Something done';
end;
end.
*************************************************************************
Main Unit (Demographics;)
unit Demographics;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Final, stringcheck;
//uses stringcheck.pas
type
TForm2 = class(TForm)
Name: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FinalVal(Sender: TObject);
private
{ Private declarations }
public
SharedData: TForm1;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FinalVal(Sender: TObject);
begin
ShowMessage('tetss'+ IntToStr(Form1.Test1));
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
ShowMessage('tetss print-'+ TSharedFunctions1.DoSomething());
//Undeclared identifier: 'TSharedFunctions1'
end;
Thanks
Sandeepan.
Sandeepan Kashyap
2014-10-07 11:41:42 UTC
Permalink
Thank you very much DoDi and Alan for your help. I worked :)
Post by Sandeepan Kashyap
Sandeepan
Look up & understand a paragraph or section entitled "Scope" in the help
file you have for whatever version of Delphi you have. It explains all this
stuff that you're having problems with.
Alan Lloyd
Post by Sandeepan Kashyap
Hi,
we are trying to access a function DoSomething() of unit stringcheck from
'TSharedFunctions1' error, not sure why? though we have used the unit in
main Unit.
Any ideas will be greatly appreciated.
unit stringcheck;
interface
implementation
{$R *.RES}
uses sysutils ,StrUtils;
type
TSharedFunctions1 = class
public
function DoSomething: string;
end;
function TSharedFunctions1.DoSomething: string;
begin
Result := 'Something done';
end;
end.
*************************************************************************
Main Unit (Demographics;)
unit Demographics;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, Final, stringcheck;
//uses stringcheck.pas
type
TForm2 = class(TForm)
Name: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FinalVal(Sender: TObject);
private
{ Private declarations }
public
SharedData: TForm1;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FinalVal(Sender: TObject);
begin
ShowMessage('tetss'+ IntToStr(Form1.Test1));
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
ShowMessage('tetss print-'+ TSharedFunctions1.DoSomething());
//Undeclared identifier: 'TSharedFunctions1'
end;
Thanks
Sandeepan.
Loading...