07-25-2023, 09:43 AM
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.
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.