Discussion:
Getting error- Declaration of 'StringReturn' differs from previous declaration
(too old to reply)
Sandeepan Kashyap
2014-10-09 07:17:55 UTC
Permalink
hi,

Earlier, I called a function StringReturn (without a parameter passed) from Unit1, and it returned the value from Unit2 function and showed it over a popup to me without any issue.

However, now when I passes a parameter 'passedString', it's giving me the below error, not sure why, though I have passed the parameters in a correct format.
[Error] stringcheck.pas(27): Declaration of 'StringReturn' differs from previous declaration


Unit1
ShowMessage('Piece function-'+ obj.StringReturn(passedString));

Unit2
function TSharedFunctions1.StringReturn(passedString: string): string;



Thanks!

Sandeepan
JJ
2014-10-09 15:38:05 UTC
Permalink
Post by Sandeepan Kashyap
function TSharedFunctions1.StringReturn(passedString: string): string;
Make sure that class method declaration matched the one in the interface
block.
Sandeepan Kashyap
2014-10-10 06:13:47 UTC
Permalink
Thanks JJ, I believe I have used the class object-TSharedFunctions1 correctly. Below is the code. Am I still missing something?

unit Demographics;
procedure TForm2.Button3Click(Sender: TObject);{
var
passedString : string;
begin
var
passedString:= Edit3.Text;
ShowMessage('Piece function-'+ obj.StringReturn(passedString));
end;

********************************************************************
unit stringcheck;
interface
type
TSharedFunctions1 = class
private
public
Result : unit Demographics;string;
function DoSomething: string;
function StringReturn: string;
end;

function TSharedFunctions1.StringReturn(passedString: string): string;
begin
.
.
end;
JJ
2014-10-10 16:00:32 UTC
Permalink
Basically, the implementation part of a class method must match exactly with
the method that was declared in the class type. i.e. this is the
declaration.
Post by Sandeepan Kashyap
type
TSharedFunctions1 = class
public
function StringReturn: string;
end;
Which means that the "StringReturn" method *does not* have any parameter.

Now this is the implementation.
Post by Sandeepan Kashyap
function TSharedFunctions1.StringReturn(passedString: string): string;
begin
.
.
end;
You can see that it has one parameter. This difference is not allowed by the
compiler. If you know function overloading, then use that. Otherwise fix it
so that both have exact the same number of parameters, name of each
parameters, type of each parameters, and the return type.
Sandeepan Kashyap
2014-10-13 05:45:00 UTC
Permalink
Aaaww! I see! Evidently, I missed them there. It's working fine now.
Thanks for your help. :)

Sandeepan

Loading...