stos zapomocą tablicy dynamicznej

0

Witam
Jestem trochę beginner w delphi i pare chwil temu napisałem sobie taki kodzik(stos zapomocą tablicy dynamicznej. Jednak już napoczątku nie działa mi np constructor Init. Jeśli zauważycie jakieś błędy plz help.

Moduł 1

unit Unit2;

interface
 type
    elementtype     = String[10];
 
   TAStack = class(TObject)

        private

            Stack : array of elementtype; //dynamiczna tablica  elementów
            Top     : Longint;           // szczyt stosu
            NumAllocated : Longint;      // pojemność stosu
            procedure ResizeStack;

        public
            
            destructor MakeNull;
            constructor Init;
            procedure Push(x : Elementtype);
            procedure Pop;
            function  Empty : Boolean;
            function  TopElem : Elementtype;
            function  ToText: String;
    end;

implementation

constructor TAStack.Init;
begin
 inherited Create;
 SetLength(Stack, 10);
 NumAllocated:=10;
 top:=-1;
end;

destructor TAStack.MakeNull;
begin
 inherited destroy;
end;

procedure TAStack.ResizeStack;
begin
 if NumAllocated-1<=top then   begin inc(NumAllocated);  SetLength(Stack, NumAllocated); end;
end;

procedure TAStack.Push(x : Elementtype);
begin
 ResizeStack;
 inc(top);
 Stack[top]:=x;
end;

procedure TAStack.Pop;
begin
  if not Empty then dec(top);
end;

function  TAStack.Empty : Boolean;
begin
Result:=FALSE;
if top=-1 then RESULT:=TRUE;
end;

function  TAStack.TopElem : Elementtype;
begin
Result:=Stack[top];
end;

function  TAStack.ToText: String;
const CR=#13#10;
var i:byte;
begin
  for i:=0 to top do Result:=Result+CR+Stack[i];

end;


end.

A tutaj część do obsługi buttonów , na razie tylko z tym nieszczęsliwym constructorem.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Unit2;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    BInit: TButton;
    BMakeNull: TButton;
    BPUSH: TButton;
    BPOP: TButton;
    Btopelement: TButton;
    Memo1: TMemo;
    procedure BInitClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  
implementation

{$R *.dfm}
var    S : TAStack;


procedure TForm1.BInitClick(Sender: TObject);
begin
S.Init;
end;

end.
0

S:= TAStack.Init;

:>

0

Dzięki -głupi błąd :-) późno już było

1 użytkowników online, w tym zalogowanych: 0, gości: 1