Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-02

Overloading methods of a parent class

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth

Hello together!

I'm currently trying to implement the overloading of methods in class helpers, but I now have the problem that I don't know where I should touch the compiler.
So my question is the following: How does overloading methods that are defined in different (but related) classes work in the compiler?

Following example:

TClass1 = class
   procedure Test(aValue: Integer); overload;
end;
TClass2 = class(TClass1)
   procedure Test(aValue: String); overload;
end;
var
   c: TClass2;
begin
   c.Test(42);
end.

Where does the compiler decide which method to call? And how does the compiler know which methods are available?
The latter question can be understand as: Does the compiler search the correct symtable (in this case that for TClass1) when it parses the factor "c.Test" or does it resolve that already when parsing the definition of TClass2?

I'll continue searching the correct spot nevertheless.

Regards,
Sven

Reply by email

Florian Klaempfl
to Sven Barth
Sven Barth wrote
The latter question can be understand as: Does the compiler search the correct symtable (in this case that for TClass1) when it parses the factor "c.Test"

Yes.

or does it resolve that already when parsing the definition of TClass2?

No.

I'll continue searching the correct spot nevertheless.

The class tcallcandidates in htypechk.pas does basically the work.

Reply by email

Sven Barth
to Florian Klaempfl
Florian Klaempfl wrote 16 lines
Am 09.02.2011 10:43, schrieb Sven Barth: > The latter question can be understand as: Does the compiler search the > correct symtable (in this case that for TClass1) when it parses the > factor "c.Test" Yes. > or does it resolve that already when parsing the > definition of TClass2? No. > > I'll continue searching the correct spot nevertheless. The class tcallcandidates in htypechk.pas does basically the work.

Thank you.

Regards,
Sven

Reply by email