Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Method overriding problem (compiler and efficiency problem)

0 views
Skip to first unread message

Jaelani

unread,
Aug 26, 2007, 7:58:53 AM8/26/07
to
Hello, I have a problem about the compiled code of the overriden
method. Here's a very simple example:

---start of code---
TBaseClass= class
public
procedure Calculate; virtual;
function GetResult: integer; //this function uses above Calculate
procedure
end;

TNewClass= class(TBaseClass)
public
procedure Calculate; override;
end;

var MyClass: TNewClass;

begin
MyClass:= TNewClass.Create;
end.
---end of code---

While the code works fine and correctly, the TBaseClass.Calculate is
still compiled by the compiler even though it is not used. In other
words, the compiler doesn't eliminate unused code.

I've already tried enabling the optimization and disabling all of
debugging compiler directives, but no difference... the
TBaseClass.Calculate is still compiled and included in the binary.

I also tried to use dynamic method, but no difference also. While
using the abstract method can solve the problem, it will requires
significant changes in both the class and the application and it is
one thing I won't do.

Or even tried using conditional directives, but that also will need
significant changes in the code.

Any solution or workaround for this?
Thank you in advance.

_______
Jaelani

Jaelani

unread,
Aug 26, 2007, 8:03:29 AM8/26/07
to
Jaelani wrote:
>
> begin
> MyClass:= TNewClass.Create;
> end.

Correction for the above code:

begin
MyClass:= TNewClass.Create;
MyClass.GetResult;
MyClass.Free;
end.

HeartWare

unread,
Aug 27, 2007, 1:22:25 AM8/27/07
to
On Aug 26, 1:58 pm, Jaelani <jaelan...@gmail.com> wrote:

> Any solution or workaround for this?

No - virtual/dynamic functions cannot be smart-linked out. To detect
whether or not they are actually used at run-time is too complex for
the compiler.

0 new messages