QP School
Object-oriented concepts in Object Pascal - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Object Pascal Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=50)
+--- Thread: Object-oriented concepts in Object Pascal (/showthread.php?tid=5048)



Object-oriented concepts in Object Pascal - Qomplainerz - 07-25-2023

program ObjectOrientedExample;
type
  // Define a simple class representing a person
  TPerson = class
  private
    FName: string;
    FAge: Integer;
  public
    constructor Create(const AName: string; AAge: Integer);
    procedure SayHello;
  end;

constructor TPerson.Create(const AName: string; AAge: Integer);
begin
  FName := AName;
  FAge := AAge;
end;

procedure TPerson.SayHello;
begin
  WriteLn('Hello, my name is ', FName, ' and I am ', FAge, ' years old.');
end;

var
  Person: TPerson;
begin
  // Create an instance of TPerson
  Person := TPerson.Create('John', 30);

  // Call the SayHello method
  Person.SayHello;

  // Free the memory allocated for the object
  Person.Free;
end.