BILL
BILL

Reputation: 4869

How to correctly define function on Delphi?

I have this function declaration and implementation

public
function AddWordReference(wordId,translateId:Longint):Longint;
{***}
function AddWordReference(wordId,translateId:Longint):Longint;
begin
try
 if((wordId <> -1) OR (translateId <> -1))  Then
 begin
 DataModule1.TranslateDictionary.AppendRecord([nil,wordId,translateId]);
 DataModule1.TranslateDictionary.Last;
 AddWordReference := DataModule1.TranslateDictionary.FieldByName('Id').AsInteger;
 end;
Except
ShowMessage('Error wirh adding reference');
AddWordReference := -1;
end;
AddWordReference := -1;
end;

I have this error:

[Error] AddFormUnit.pas(34): Unsatisfied forward or external declaration: 'TForm2.AddWordReference'

How to fix this error ?

Upvotes: 1

Views: 3776

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596256

It is a member of your TForm2 class, so in the implementation section, you have to declare it as TForm2.AddWordReference instead of just AddWordReference. And then inside the method itself, you should be assigning your return value to the compiler's Result variable instead of the AddWordReference method name:

public
  function AddWordReference(wordId, translateId: Longint): Longint;

.

function TForm2.AddWordReference(wordId, translateId: Longint): Longint;
begin
  Result := -1;
  try
    if (wordId <> -1) OR (translateId <> -1) then
    begin
      DataModule1.TranslateDictionary.AppendRecord([nil, wordId, translateId]);
      DataModule1.TranslateDictionary.Last;
      Result := DataModule1.TranslateDictionary.FieldByName('Id').AsInteger;
    end;
  except
    ShowMessage('Error wirh adding reference');
  end;
end;

Upvotes: 12

Related Questions