Respond to an unknown method call: Difference between revisions

Line 493:
An exception about calling a virtual method will be raised and interrupt the current code flow. But in that situation, the function is actually known. The concept of a function not being known at all does not exist in Object Pascal, due to static name lookup checking. That is to say, the call a.b() causes the compiler to verify that the symbol b exists in the namespace associated with expression a, and refers to a function.
 
To avoid the possibility of an abstract method call, one common solution is to leave an empty implementation for the virtual method instead of making it abstract,. likeThis thisis what an abstract method call looks like:
 
<lang pascal>
Line 499:
Tanimal = class
public
procedure bark(); virtual; // virtual, but not abstract;
end;
 
implementation
 
procedure Tanimal.bark();
begin
end;
 
var
Line 514 ⟶ 510:
 
animal := Tanimal.Create;
animal.bark(); // abstract method call exception at runtime here
animal.Free;