Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overload Problem

Status
Not open for further replies.

6volt

Programmer
Jun 4, 2003
74
US
The following code works perfectly if I use 2 different PROCEDURE names and no OVERLOADing.

When I attempt the OVERLOAD, I get the error,

"There is no overloaded version of 'AssignPcode' that can be called with these arguments."

Here is the code:

[tt]
unit U_overload;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
IntMatrix = array[0..10,0..4] of Integer;
TForm1 = class (TForm)
PROCEDURE FormCreate (Sender : TObject);
private
public
end;

VAR
Form1: TForm1;

gPcode : Integer;
gP : Array[0..4] of Integer;
allPcode : Array[0..4] of Integer;
allP : IntMatrix;

PROCEDURE AssignPcode ( code:Integer ;
VAR P:Array of Integer ); OVERLOAD;

PROCEDURE AssignPcode ( Pcode:Array of Integer ;
VAR Q:IntMatrix ;
n:Integer ); OVERLOAD;
implementation
{$R *.DFM}
//_________________________________________________________
PROCEDURE TForm1.FormCreate(Sender: TObject);
VAR
n : Integer;

BEGIN
gPcode := 10000;
allPcode [0] := 11111;
allPcode [1] := 2;
allPcode [2] := 30000;

n :=3;
AssignPcode ( gPcode, gP );
AssignPcode ( allPcode, allP, n );

ShowMessage (inttostr( gP[ 0])+#13+inttostr( gP[ 4]));
ShowMessage (inttostr(allP[0,0])+#13+inttostr(allP[3,0]));
END;
//_________________________________________________________
PROCEDURE AssignPcode ( code : Integer ;
VAR P: Array of Integer ); OVERLOAD;
BEGIN
P[0] := (code mod 100000) div 10000;
P[4] := (code mod 10 ) div 1 ;
END;
//_________________________________________________________
PROCEDURE AssignPcodf (Pcode : Array of Integer ;
VAR Q : IntMatrix ;
n : Integer );OVERLOAD;
VAR
i : Integer;
BEGIN
FOR i := 0 TO n-1 DO BEGIN
Q[i,0] := (Pcode mod 100000) div 10000;
Q[i,4] := (Pcode mod 10 ) div 1 ;
END;
END;
END.
[/tt]







 

Not sure if this is the only problem, but don't specify "overload" on the implementation -- only use it for the prototype in the interface section.

 
Thanks for suggestion, however still get same error.

PS. My favorite quote, Zathras say, "Never use this...
 

It's always the little things that trip us up. -- You have the second implementation of the function spelled AssignPcodf instead of AssignPcode.

You first clue is to read the warning message "Unsatisfied forward or external declaration: 'AssignPCode' and then double-click on it to see which statement it is talking about -- in this case it takes you to the second one.

 
Good eyes, except that was a typo from a previous switch from w/o OVERLOAD to w/OVERLOAD.

I corrected it and it still does the same thing.

THOUGHT 1:

I was thinking that the definition of OVERLOAD they say compiler distinguishes between 1) number of parms, OR 2) parm types.

If taken literally, with a different number, perhaps the types have to be the same.

THOUGHT 2:

I wonder if "array of" is confusing it.

Can it see the difference between Integer and Array of Integer.

To force it to see 2 different types, I could define an Array Type.

I'm in the middle of something else, but that experiment is doable.
 

Hmmm. It compiled for me as is with the one spelling change (Delphi 7). What version of Delphi are you using?

Where do you go when you double-click on the error message. That message usually means you are executing the procedure from somewhere but don't have the parameters matching up correctly. I think you need to post more of the code.

 
hummmmm... I'm using Delphi 5.

The error came on the 1st call to the procedure.

I'm at home now, I'll have more on this when I go back to office.

Interesting.
 
I've just tried it in Delphi 6 Pro and it works fine as follows (without overload statements in implementation and with typo fixed). Here's the whole unit:
Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  IntMatrix = array[0..10, 0..4] of Integer;

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  gPcode   : Integer;
  gP       : Array[0..4] of Integer;
  allPcode : Array[0..4] of Integer;
  allP     : IntMatrix;

procedure AssignPcode(code: Integer; var P: Array of Integer); overload;
procedure AssignPcode(Pcode: Array of Integer; var Q: IntMatrix; n: Integer); overload;

implementation

{$R *.dfm}

procedure AssignPcode(code: Integer; var P: Array of Integer);
begin
  P[0] := (code mod 100000) div 10000;
  P[4] := (code mod 10) div 1;
end;

procedure AssignPcode(Pcode: Array of Integer; var Q: IntMatrix; n: Integer);
var
  i: Integer;
begin
  for i := 0 to n - 1 do
  begin
    Q[i,0] := (Pcode[i] mod 100000) div 10000;
    Q[i,4] := (Pcode[i] mod 10) div 1;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
   n: Integer;
begin
  gPcode := 10000;
  allPcode[0] := 11111;
  allPcode[1] := 2;
  allPcode[2] := 30000;

  n := 3;
  AssignPcode(gPcode, gP);
  AssignPcode(allPcode, allP, n);

  ShowMessage(IntToStr(gP[0]) + #13 + IntToStr(gP[4]));
  ShowMessage(IntToStr(allP[0,0]) + #13 + IntToStr(allP[3,0]));
end;

end.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
The error came on the 1st call to the procedure.
That's my point. The problem is not in this unit. The problem is at the place where you are calling one of these procedures.

If I had to guess, I would say you probably didn't include this unit in your uses clause in the unit where you are calling one of these procedures.

 
Hummmmm... this is strange:

I copied Stretch's code and compiled it only to find that Uses Variants was not found - so I removed Variants.

Still get same error.

Fixed my code with the type AND put the Overloaded Procedures in the Implementation AFTER the calling Procedure too and that didn't work.

Zathras: I don't understand your last sentence:

"If I had to guess, I would say you probably didn't include this unit in your uses clause in the unit where you are calling one of these procedures."

This is a simple stand alone test program. Its Unit1 is Used by the "boot" program that always exists to run the application but that is all as far as Uses goes.

I'm going to see if I can run this on Delphi 7.
 
RATS!

It runs in Delphi 7 w/ and w/o Uses Variants!!!!!!!!!!

What could have possibly have changed from 5 to 7 regarding this???????

(I'm not using 7 because I have Excel automations which are no longer supported in 7 and I'm in no mood to jump back in that Tar Pit again!)
 
Latest attempt in Delphi 5:

I eliminated the "Array of Integer" stuff and declared a Type IntArray. (Thinking 5 may not be smart enough to distinguish between "types" of "Integer" and "Array of Integer."

Now it compiles in 5, however hangs when F9 executed. (Hangs at Application.Run if you single step into it in IDE.)

So, I think I have stepped on one of its "nerves" but still don't have the whole picture yet.
 
..figured out hang... copied code, forgot to set OnCreate for Form...

Anyhow, it appears 5 cannot differentiate between "Integer" and "Array of Integer" whereas 7 can.

Got it to work in 5 by creating a IntArray Type.

It seems odd that 5 can't see the difference and I wouldn't swear it won't work in 5, because I may still have something wrong with that approach. However, since it does work in 7, that suggests there is a good possibility that it actually is a limitation in 5.

 
So are you up and running ok now? Incidentally, I was going to suggest making an array type but as it compiled in Delphi 6 I thought the move to 5 wouldn't need that either!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Yep, up and running.

It was an incredible waste of time. I was completely blindsided by Delphi's (Pascal's) completely different handling of multi dimensional arrays AND this parameter problem.

I always laugh that you could write everything you need to know about programming FORTRAN on a single page. (I'm 52, engineer, programming probably 250k lines of FORTRAN, and this Object Oriented changeover is PAINFULL!!!!! But the real kicker is that I get no sense of accomplishment/reward when completing a problem because I KNOW it may not work in some other environment. I mean, they have trouble getting the OS's to work!!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top