How do I call a function from another Unit
I have an app with a main form and multiple DataModules.
In the Unit for the main form (MAIN), I have a generic function GetNewId (myTable, myFieldName).
Each DataModule is listed in the Uses clause of MAIN.
Main is listed in the implimentation section of each of the DataModule units.
(The uses clauses must be set this way for other purposes)
When I try to call the GetNewId function from i procedure in a DataModule unit, I get the following Error:
[Error] DMPrayer1.pas(203): Undeclared identifier: 'GetNewId'
[Fatal Error] MAIN.PAS(12): Could not compile used unit 'DMPrayer1.pas'
Questions:
1. (Considering the above info), how might I successfully call this function (below) from within a DataModule unit?
2. If is is just a matter of declaring the function,
exactly where the declaration should go
The function in 'main' is as follows:
============begin================
Unit Main;
interface
uses
...;
type
...
end;
var
...;
implementation
uses
...;
{$R *.DFM}
function GetNewId(myTable: TTable; myFieldName: String): Integer;
Var
newId : Integer;
idFieldName : String;
begin
idFieldName := 'NewId';
myTable.Active := True;
try
myTable.Active := True;
myTable.LockTable(ltWriteLock);
myTable.LockTable(ltReadLock);
myTable.Refresh;
myTable.Edit;
newId := myTable.FieldByName(myFieldName).value;
Result := newId; //Get new Id
Inc(newId); //Set next Id
myTable.FieldByName(idFieldName).value := newId;
myTable.Post;
finally
myTable.UnlockTable(ltWriteLock);
myTable.UnlockTable(ltReadLock);
myTable.Refresh;
myTable.Active := False;
end;
end;
...
Tim
tim@tgm.org
I have an app with a main form and multiple DataModules.
In the Unit for the main form (MAIN), I have a generic function GetNewId (myTable, myFieldName).
Each DataModule is listed in the Uses clause of MAIN.
Main is listed in the implimentation section of each of the DataModule units.
(The uses clauses must be set this way for other purposes)
When I try to call the GetNewId function from i procedure in a DataModule unit, I get the following Error:
[Error] DMPrayer1.pas(203): Undeclared identifier: 'GetNewId'
[Fatal Error] MAIN.PAS(12): Could not compile used unit 'DMPrayer1.pas'
Questions:
1. (Considering the above info), how might I successfully call this function (below) from within a DataModule unit?
2. If is is just a matter of declaring the function,
exactly where the declaration should go
The function in 'main' is as follows:
============begin================
Unit Main;
interface
uses
...;
type
...
end;
var
...;
implementation
uses
...;
{$R *.DFM}
function GetNewId(myTable: TTable; myFieldName: String): Integer;
Var
newId : Integer;
idFieldName : String;
begin
idFieldName := 'NewId';
myTable.Active := True;
try
myTable.Active := True;
myTable.LockTable(ltWriteLock);
myTable.LockTable(ltReadLock);
myTable.Refresh;
myTable.Edit;
newId := myTable.FieldByName(myFieldName).value;
Result := newId; //Get new Id
Inc(newId); //Set next Id
myTable.FieldByName(idFieldName).value := newId;
myTable.Post;
finally
myTable.UnlockTable(ltWriteLock);
myTable.UnlockTable(ltReadLock);
myTable.Refresh;
myTable.Active := False;
end;
end;
...
Tim
tim@tgm.org