program SimpleFPCOOP;
{$mode objfpc}{$H+}
uses
Classes, fgl;
type
generic TList<T> = class
Items: array of T;
procedure Add(Value: T);
function Get(i: integer): T;
function GetLength: integer;
end;
TIntegerList = specialize TList<integer>;
procedure TList.Add(Value: T);
begin
SetLength(Items, Length(Items) + 1);
Items[Length(Items) - 1] := Value;
end;
function Tlist.Get(i: integer): T;
begin
result := Items[i];
end;
function Tlist.GetLength: integer;
begin
result := Length(Items);
end;
type
TSelbst = class(TObject)
private
fWert : integer;
fWerte: TIntegerList;
public
constructor Create(w: integer);
function GetWert: integer;
procedure AddWert(w: integer);
end;
constructor TSelbst.Create(w: integer);
begin
fWert := w;
fWerte := TIntegerList.Create;
fWerte.Add(w);
end;
procedure TSelbst.AddWert(w: integer);
begin
fWerte.Add(w);
end;
function TSelbst.GetWert: integer;
begin
result := fWerte.Get(fWerte.GetLength - 1);
end;
var
fremd: TSelbst;
begin
fremd := TSelbst.Create(7);
WriteLn(fremd.GetWert);
fremd.AddWert(27);
WriteLn(fremd.GetWert);
ReadLn;
end.
cHJvZ3JhbSBTaW1wbGVGUENPT1A7Cgp7JG1vZGUgb2JqZnBjfXskSCt9Cgp1c2VzCiAgQ2xhc3NlcywgZmdsOwp0eXBlCiAgZ2VuZXJpYyBUTGlzdDxUPiA9IGNsYXNzCiAgICBJdGVtczogYXJyYXkgb2YgVDsKICAgIHByb2NlZHVyZSBBZGQoVmFsdWU6IFQpOwogICAgZnVuY3Rpb24gR2V0KGk6IGludGVnZXIpOiBUOwogICAgZnVuY3Rpb24gR2V0TGVuZ3RoOiBpbnRlZ2VyOwogIGVuZDsKCiAgVEludGVnZXJMaXN0ID0gc3BlY2lhbGl6ZSBUTGlzdDxpbnRlZ2VyPjsKCiAgcHJvY2VkdXJlIFRMaXN0LkFkZChWYWx1ZTogVCk7CiAgYmVnaW4KICAgIFNldExlbmd0aChJdGVtcywgTGVuZ3RoKEl0ZW1zKSArIDEpOwogICAgSXRlbXNbTGVuZ3RoKEl0ZW1zK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