2

Здравствуйте уважаемые, пытаюсь использовать динамический массив внутри класса. Но ничего не выходит. Подскажите, в чём ошибка?

Основной файл:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Unit1 in 'Unit1.pas';

var test: TMyClass;
begin
  {TODO -oUser -cConsole Main : Insert code here }

   test.Add(43);
   Readln;

end.

Unit1

unit Unit1;

interface

type 
    TMyClass = class(TObject)
    public
    myArray: array of Integer;

  procedure Add( n: integer );
    end;

implementation

    procedure TMyClass.Add;
        begin
       SetLength( myArray, 1 );

           Writeln( 'Okay' );
        end;
end.

Комппилятор выдаёт: [Warning] Project2.dpr(14): Variable 'test' might not have been initialized

1 ответ 1

5

Вы забыли создать экземпляр класса.

заменить:

test.Add(43);

на:

test := TMyClass.Create;
test.Add(43);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.