Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Не хочет вызываться нужный конструктор класса


Мирон ©   (2005-03-01 00:44:00) 

Есть такое дело:

...
TAboutDocument = class(TDocument)
private
 FList: TList;
public
 constructor Creare; override;
 property List: TList read FList;
end;

TDocumentClass = class of TDocument;
...

TRegime = class(TObject)
private
...
 FDocument: TDocument;
 function DocumentClass: TDocumentClass; virtual; abstract;
...
public
 constructor Create;
end;

TAboutRegime = class(TRegime)
...
 function DocumentClass: TDocumentClass; override;
...
end;

constructor TAboutDocument.Create;
begin
 inherited;
 FList := TList.Create;
end;

constructor TRegime.Create;
begin
 inherited;
 FDocument := DocumentClass.Create;
 ...
end;

function TAboutRegime.DocumentClass: THTMLDocumentClass;
begin
 Result := TAboutDocument;
end;


Так вот, во время TAboutRegime.Createпри выполнении строки FDocument := DocumentClass.Create; конструктор TAboutDocument не выполнятеся вообще... Хотя после этой строки FDocument <> nil, но в то же время FDocument.List = nil... Не пойму, почему такое твориться...


Юрий Зотов   (2005-03-01 01:48:00) [1]

Вот так все работает. Практически то же самое, что и у Вас, (только немного причесано), поэтому в чем причина - непонятно. Вероятно, в том коде, который не приведен.

type
 TDocument = class
   constructor Create; virtual;
 end;

 TDocumentClass = class of TDocument;

 TAboutDocument = class(TDocument)
 private
   FList: TList;
 public
   constructor Create; override;
   destructor Destroy; override;
   property List: TList read FList;
 end;

 TRegime = class
 private
   FDocument: TDocument;
 protected
   class function DocumentClass: TDocumentClass; virtual; abstract;
 public
   constructor Create;
   destructor Destroy; override;
 end;

 TAboutRegime = class(TRegime)
 protected
   class function DocumentClass: TDocumentClass; override;
 end;

 TForm1 = class(TForm)
   procedure FormClick(Sender: TObject);
 end;

{ TDocument }

constructor TDocument.Create;
begin
 inherited Create
end;

{ TAboutDocument }

constructor TAboutDocument.Create;
begin
 inherited;
 FList := Tlist.Create
end;

destructor TAboutDocument.Destroy;
begin
 FList.Free;
 inherited
end;

{ TRegime }

constructor TRegime.Create;
begin
 inherited;
 FDocument := DocumentClass.Create;
end;

destructor TRegime.Destroy;
begin
 FDocument.Free;
 inherited
end;

{ TAboutRegime }

class function TAboutRegime.DocumentClass: TDocumentClass;
begin
 Result := TAboutDocument
end;

{ TForm1 }

procedure TForm1.FormClick(Sender: TObject);
begin
 TAboutRegime.Create.Free
end;


Мирон   (2005-03-01 00:52:00) [2]

блин, и внизу...

читать правильно

function TAboutRegime.DocumentClass: TDocumentClass;
begin
Result := TAboutDocument;
end;


Мирон   (2005-03-01 00:51:00) [3]

Димон   (01.03.05 0:48) [1]
опечатался... Create...


Димон   (2005-03-01 00:48:00) [4]

ты не опечатался
creare или create?


Наверх

Титульная страница Поиск, карта сайта Написать письмо