1
0
lazarus-tutorials/simple_examples/class_intro.pas

45 lines
879 B
ObjectPascal
Raw Permalink Normal View History

2021-10-04 14:33:07 -04:00
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.