Use function in DataModule
I have a datamodule (TfDB), I would like to add this function to it
Function GetZone(zone :string):string;
When I try to run it I get this error ... Unhappy appearance of external declaration: TfDB.GetZone
unit MyDataModule;
interface
uses
System.SysUtils, System.Classes, Data.DB, Data.Win.ADODB;
type
TfDB = class(TDataModule)
dbconnection: TADOConnection;
private
{ Private declarations }
public
Function GetZone(zone :string):string;
end;
var
fDB: TfDB;
implementation
{%CLASSGROUP 'System.Classes.TPersistent'}
{$R *.dfm}
Function GetZone(zone:string):string;
begin
if zone = 'FLayout1' then
result := '1';
if zone = 'FLayout2' then
result := '2';
if zone = 'FLayout3' then
result := '3';
if zone = 'FLayout4' then
result := '4' ;
if zone = 'FBoneYard' then
result := 'BoneYard';
if zone = 'FShop' then
result := 'shop';
if zone = 'FMisc' then
result := 'Misc' ;
end;
end.
+3
Glen morse
source
to share
1 answer
In the implementation section, you need to declare the function as a class method:
function TfDB.GetZone(zone:string):string;
begin
....
end;
Your expression looked like this:
function GetZone(zone:string):string;
begin
....
end;
And that defines a standalone function, not a class method.
+5
David Heffernan
source
to share