1
0
Fork 0
lazarus-tutorials/simple_examples/class_intro.pas

45 lines
879 B
ObjectPascal

program class_intro;
{$mode objfpc}{$H+}
type TGrandParent = class(TObject)
procedure WriteAboutMyself;
end;
procedure TGrandParent.WriteAboutMyself;
begin
WriteLn();
WriteLn('The name of this class is ', self.ClassName);
WriteLn(' its parent is ', self.ClassParent.ClassName);
WriteLn(' its InstanceSize is ', self.InstanceSize);
WriteLn(' its declaration is located in ', Self.UnitName);
end;
type
TParent = class(TGrandParent)
FintField: integer;
end;
TChild = class(TParent)
FsetField: set of byte;
end;
var exampleClass: TGrandParent;
begin
exampleClass := TGrandParent.Create;
exampleClass.WriteAboutMyself;
exampleClass.Free;
exampleClass := TParent.Create;
exampleClass.WriteAboutMyself;
exampleClass.Free;
exampleClass := TChild.Create;
exampleClass.WriteAboutMyself;
exampleClass.Free;
{$IFDEF WINDOWS}
ReadLn;
{$ENDIF}
end.