Event Virtual



Event Virtual
Smart pascal source code
type TBase = class Field: Integer; procedure Event(s: String); virtual; begin WriteLn('Base ' + s + ' ' + IntToStr(Field) + ' ' + ClassName); end; end; type TChild = class(TBase) procedure Event(s: String); override; begin WriteLn('Child ' + s + ' ' + IntToStr(Field) + ' ' + ClassName); end; end; type TSubChild = class(TChild) end; { main.pas } Begin var e: procedure(s: String); var b := new TBase; var c := new TChild; var s := new TSubChild; b.Field := 1; c.Field := 2; s.Field := 3; e := b.Event; e('a'); e := c.Event; e('b'); e := s.Event; e('c'); e := TBase(c).Event; e('d'); e := TBase(s).Event; e('f'); e := TChild(s).Event; e('g'); { <<< CONSOLE OUTPUTS >>> Base a 1 TBase Child b 2 TChild Child c 3 TSubChild Child d 2 TChild Child f 3 TSubChild Child g 3 TSubChild }