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

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

Уничтожение массива компонентами ...


Страницы:   1 2 3

4ort ©   (2008-04-16 13:05:00) 

доброе всем утро.
возникла проблема при удалении объектов...помогите решить
есть класс типа:
 TMyClass = class
   A : TLabel;
   B : TImage;
   constructor Create (Parent : TWinControl);
   destructor Free;
 end;

есть массив:

 Arr : array of TMyClass;

так вот - при уделении пытаюсь делать так:

 If Length (Arr) > 0 then begin
   For I:=0 to Length (Arr) - 1 do begin
     If Assigned (Arr[I]) then begin
       Arr[I].Free;
     end;
   end;
   SetLength (Arr, 0);
 end;

В деструкторе написано:

destructor TMyClass.Free;
begin
 A.Free;
 B.Free;
end;

Но моя прога при этом зависает, не выдавая никаких ошибок, просто тупо виснет... Как быть?


Kolan   (2008-04-16 13:41:00) [21]

Надо не так:
> TMyClass = class
>   A : TLabel;
>   B : TImage;
>   constructor Create (Parent : TWinControl);
>   destructor Free;
> end;


А как минимум так:

TMyClass = class
 A : TLabel; {


Dennis I. Komarov   (2008-04-16 13:40:00) [22]

> [27] 4ort   (16.04.08 13:37)

Не-а


4ort   (2008-04-16 13:40:00) [23]

Я в Делфях недавно и непредставляю что имеется ввиду под отладчиком, если это про интерпритатор, то он молчит как партизан ... ))))


Kolan   (2008-04-16 13:39:00) [24]

> вот конструкор

Что ты знаешь про фреймы ? :)


Сергей М.   (2008-04-16 13:37:00) [25]


> 4ort


Ну так все же чтоговорит отладчик?


4ort   (2008-04-16 13:37:00) [26]

Kolan ©   (16.04.08 13:35) [24]

В [21] я поправился )))


4ort   (2008-04-16 13:36:00) [27]

вот конструкор

constructor TTenderPreview_Body.Create (Parent : TWinControl);
begin
 BodyShape := TShape.Create (Parent);
 BodyShape.Visible := false;
 BodyShape.Parent := Parent;
 BodyShape.Brush.Color := clWhite;
 BodyShape.Pen.Color := 1720308;

 SectionShape := TShape.Create (Parent);
 SectionShape.Visible := false;
 SectionShape.Parent := Parent;
 SectionShape.Brush.Color := clWhite;
 SectionShape.Pen.Color := 1720308;

 DemandShape := TShape.Create (Parent);
 DemandShape.Visible := false;
 DemandShape.Parent := Parent;
 DemandShape.Brush.Color := clWhite;
 DemandShape.Pen.Color := 1720308;

 TenderTitleShape := TShape.Create (Parent);
 TenderTitleShape.Visible := false;
 TenderTitleShape.Parent := Parent;
 TenderTitleShape.Brush.Color := 867282;
 TenderTitleShape.Pen.Color := 9933;

 TenderTitle := TLabel.Create(Parent);
 TenderTitle.Parent := Parent;
 TenderTitle.Visible := false;
 TenderTitle.Font.Color := clWhite;
 TenderTitle.Font.Style := [fsBold];
 TenderTitle.Transparent := true;
 TenderTitle.Caption := 'Заявка';

 TenderIDText := TLabel.Create(Parent);
 TenderIDText.Parent := Parent;
 TenderIDText.Visible := false;
 TenderIDText.Font.Color := clWhite;
 TenderIDText.Font.Style := [];
 TenderIDText.Transparent := true;

 NeedText := TLabel.Create(Parent);
 NeedText.Parent := Parent;
 NeedText.Visible := false;
 NeedText.Font.Color := clBlack;
 NeedText.Font.Size := 4;
 NeedText.Font.Style := [];
 NeedText.Transparent := true;

 RegionTitle := TLabel.Create(Parent);
 RegionTitle.Parent := Parent;
 RegionTitle.Visible := false;
 RegionTitle.Font.Color := clBlack;
 RegionTitle.Font.Size := 4;
 RegionTitle.Font.Style := [fsBold];
 RegionTitle.Transparent := true;
 RegionTitle.Caption := 'Регион: ';

 RegionText := TLabel.Create(Parent);
 RegionText.Parent := Parent;
 RegionText.Visible := false;
 RegionText.Font.Color := clBlack;
 RegionText.Font.Size := 4;
 RegionText.Font.Style := [];
 RegionText.Transparent := true;

 TitleText := TLabel.Create(Parent);
 TitleText.Parent := Parent;
 TitleText.Visible := false;
 TitleText.Font.Color := 7151;
 TitleText.Font.Size := 12;
 TitleText.Font.Style := [fsBold];
 TitleText.Transparent := true;
 TitleText.Cursor := crHandPoint;
//  TitleText.OnClick := TitleClick;
//  TitleText.OnMouseEnter := TitleMouseEnter;
//  TitleText.OnMouseLeave := TitleMouseLeave;

 TitleShape := TShape.Create (Parent);
 TitleShape.Visible := false;
 TitleShape.Parent := Parent;
 TitleShape.Brush.Color := 15397107;
 TitleShape.Pen.Color := 15397107;

 AddToFavText := TLabel.Create(Parent);
 AddToFavText.Visible := false;
 AddToFavText.Parent := Parent;
 AddToFavText.Font.Color := clWhite;
 AddToFavText.Cursor := crHandPoint;
 If FavMode then
   AddToFavText.Caption := ' - удалить из избранного'
 else
   AddToFavText.Caption := ' + добавить в избранное';

 TextText := TLabel.Create(Parent);
 TextText.Parent := Parent;
 TextText.Visible := false;
 TextText.Font.Color := clBlack;
 TextText.Font.Size := 10;
 TextText.Font.Style := [];
 TextText.Transparent := true;

 im_CloseDate := TImage.Create(Parent);
 im_CloseDate.Parent := Parent;
 im_CloseDate.Picture := MainForm.im_CloseDate.Picture;
 im_CloseDate.Visible := false;
 im_CloseDate.AutoSize := true;

 im_OpenDate := TImage.Create(Parent);
 im_OpenDate.Parent := Parent;
 im_OpenDate.Picture := MainForm.im_OpenDate.Picture;
 im_OpenDate.Visible := false;
 im_OpenDate.AutoSize := true;

 OpenDateText := TLabel.Create(Parent);
 OpenDateText.Parent := Parent;
 OpenDateText.Visible := false;
 OpenDateText.Font.Color := clBlack;
 OpenDateText.Font.Size := 4;
 OpenDateText.Font.Style := [];
 OpenDateText.Transparent := true;

 CloseDateText := TLabel.Create(Parent);
 CloseDateText.Parent := Parent;
 CloseDateText.Visible := false;
 CloseDateText.Font.Color := clBlack;
 CloseDateText.Font.Size := 4;
 CloseDateText.Font.Style := [];
 CloseDateText.Transparent := true;

 SectionText := TLabel.Create(Parent);
 SectionText.Parent := Parent;
 SectionText.Visible := false;
 SectionText.Font.Color := 16711752;
 SectionText.OnMouseEnter := SectionMouseEnter;
 SectionText.OnMouseLeave := SectionMouseLeave;
 SectionText.OnClick := SectionClick;
 SectionText.Font.Size := 4;
 SectionText.Font.Style := [];
 SectionText.Transparent := true;
 SectionText.Cursor := crHandpoint;

 im_Demand := TImage.Create(Parent);
 im_Demand.Parent := Parent;
 im_Demand.AutoSize := true;
 im_Demand.Visible := false;
 im_Demand.Cursor := crHandPoint;
//  im_Demand.OnClick := DemandClick;

 im_Join := TImage.Create(Parent);
 im_Join.Parent := Parent;
 im_Join.Picture := MainForm.im_JoinTender.Picture;
 im_Join.AutoSize := true;
 im_Join.Cursor := crHandPoint;
 im_Join.OnClick := JoinClick;
 im_Join.Visible := false;
end;

Вот деструктор:

destructor TTenderPreview_Body.Destroy;
begin
 BodyShape.Free;
 SectionShape.Free;
 DemandShape.Free;
 TenderTitleShape.Free;
 TenderTitle.Free;
 TenderIDText.Free;
 NeedText.Free;
 RegionTitle.Free;
 RegionText.Free;
 TitleShape.Free;
 TitleText.Free;
 TextText.Free;
 im_OpenDate.Free;
 im_CloseDate.Free;
 im_Demand.Free;
 im_Join.Free;
 OpenDateText.Free;
 CloseDateText.Free;
 SectionText.Free;
 AddToFavText.Free;
 inherited;
end;


Kolan   (2008-04-16 13:35:00) [28]

> destructor TMyClass.Free;

Ты нормальный? Тебе в [3] сказал, что у тебя деструктор объявлен неправильно.


4ort   (2008-04-16 13:34:00) [29]

реальное описание, не очень удобное тут будет

 TTenderPreview_Body = class
   BodyShape, SectionShape, DemandShape, TenderTitleShape : TShape;
   TenderTitle, TenderIDText, NeedText, RegionTitle, RegionText,    AddToFavText : TLabel;
   TitleShape : TShape;
   TitleText, TextText : TLabel;
   im_OpenDate, im_CloseDate : TImage;
   OpenDateText, CloseDateText : TLabel;
   ID : longint;
   Visited : boolean;
   IsOnLine : boolean;
   Section, ClientID : longint;
   Title, text : string;
   NeedType, DemandType : word;
   Region : longint;
   im_Demand : TImage;
   im_Join : TImage;
   OpenDate, CloseDate : string;
   SectionText : TLabel;
   constructor Create (Parent : TWinControl);
   procedure TitleClick (Sender : TObject);
   procedure TitleMouseEnter (Sender : TObject);
   procedure TitleMouseLeave (Sender : TObject);
   procedure FavClick (Sender : TObject);
   procedure FavClickDel (Sender : TObject);
   procedure FavMouseEnter (Sender : TObject);
   procedure FavMouseLeave (Sender : TObject);
   procedure SectionMouseEnter (Sender : TObject);
   procedure SectionMouseLeave (Sender : TObject);
   procedure SectionClick (Sender : TObject);
   procedure DemandClick (Sender : TObject);
   procedure JoinClick (Sender : TObject);
   procedure Show (Width, X, Y : word);
   procedure Hide;
   destructor Destroy; override;
 end;


4ort   (2008-04-16 13:33:00) [30]

за описание класса  Сорри...там 2 лейбла,


4ort   (2008-04-16 13:32:00) [31]

destructor переделал сделал таким

destructor TMyClass.Free;
begin
 A.Free;
 B.Free;
 inherited;
end;


Kolan   (2008-04-16 13:31:00) [32]

> если наврал с терминалогией, sorry

См. [15].

[1]
B : TImage;

[17]
B := TLabel.Create (Parent);

Ты нас не обманывай, реальный код давай.


Dennis I. Komarov   (2008-04-16 13:30:00) [33]

> подразумевает под собой
>
> TMyClass = class (TObject)
> ..вроде ...

Не уверен, не знаю... Сразу написать понятно низя?


Сергей М.   (2008-04-16 13:30:00) [34]


> при теме с округлыми кнопками


Все чудесатее и чудесатее становится)

А у меня с криволинейнотрапецевидными не зависает.
Что я делаю не так ?


4ort   (2008-04-16 13:29:00) [35]

конструктор:
constructor TMyClass.Create (Parent : TWinControl);
begin
 A := TLabel.Create (Parent);
 A.Parent := Parent;
 A.Caption := 'A';
 B := TLabel.Create (Parent);
 B.Parent := Parent;
 A.Caption := 'B';
end;

код:

SetLength (Arr, 10);

For I:=0 to Length (Arr) - 1 do begin
 Arr[I] := TMyClass.Create;
end;


Dennis I. Komarov   (2008-04-16 13:28:00) [36]

> [12] Kolan ©   (16.04.08 13:25)

TMyClass = classиз [0]

если наврал с терминалогией, sorry


Kolan   (2008-04-16 13:27:00) [37]

> если бы не создавал вылетел бы Access Volation …

Наукой это не доказано :)

Показывай как создавал…


4ort   (2008-04-16 13:27:00) [38]

по умолчанию надпись

TMyClass = class

подразумевает под собой

TMyClass = class (TObject)
..вроде ...

с визуалкой недолго работаю ...


4ort   (2008-04-16 13:25:00) [39]

[10]
да создавал - то создавал - если бы не создавал вылетел бы Access Volation .. прога просто зависает и все , причем тока на WinXP, при теме с округлыми кнопками


Kolan   (2008-04-16 13:25:00) [40]

> У тебя класс, даже не наследуемый.

Это как?


Страницы:   1 2 3

Наверх

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