我有一个Packet抽象方法的类getID:
Type
Packet = class
...
function getID() : Integer;virtual;abstract;
class procedure writePacket(par0 : Packet; par1 : TIdTCPConnection);
...
implementation
class procedure Packet.writePacket(par0 : Packet; par1 : TIdTCPConnection);
// par1 is a TCP connection used to send data through the network;
begin
par1.writeInteger(par0.getID());
//some code following
end;
Run Code Online (Sandbox Code Playgroud)
我有以下子类:
type
PacketTest = class(Packet)
...
function getID() : Integer;
...
function PacketTest.getID():Integer;
begin
result := {some value individual for each subclass}
end;
Run Code Online (Sandbox Code Playgroud)
现在我writePacket用包的子类调用超类的类过程,par0然后调用子类的函数getID …