Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2008.05.18;
Скачать: [xml.tar.bz2];

Вниз

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

 
4ort   (2008-04-16 13:05) [0]

доброе всем утро.
возникла проблема при удалении объектов...помогите решить
есть класс типа:
 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;

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


 
Сергей М. ©   (2008-04-16 13:06) [1]

Воспользоваться отладчиком.


 
4ort   (2008-04-16 13:08) [2]

Я думал что дело в том что все происходит в отдельном потоке ... а нет - выдвинул в OnClick Формы - тоже самое ... (((((((


 
Kolan ©   (2008-04-16 13:10) [3]

> If Length (Arr) > 0 then begin
>   For I:=0 to Length (Arr) — 1 do begin

1. Условие нанужно, если массив пустой цикл не выполнится.
2. Правильнее использовать Low и High

If Assigned (Arr[I]) then begin
      Arr[I].Free;
Условие не нужно, оно есть во Free.

destructor TMyClass.Free;
Идиотизм, учи мат часть.


> Но моя прога при этом зависает, не выдавая никаких ошибок,
> просто тупо виснет&#133

Мне бы тоже плохо стало.


 
4ort   (2008-04-16 13:14) [4]

Kolan ©   (16.04.08 13:10) [3]

....

destructor TMyClass.Free;
Идиотизм, учи мат часть.

....

Весьма конструктивный ответ )


 
Palladin ©   (2008-04-16 13:14) [5]

Ты даже не представляешь насколько в твоем случае...


 
Dennis I. Komarov ©   (2008-04-16 13:14) [6]

> Идиотизм, учи мат часть.

+ в исходники VCL глянуть тоже никак.


 
Kolan ©   (2008-04-16 13:16) [7]

> Весьма конструктивный ответ )

Прочти первый том Тейксейры и Пачеко.
http://www.ksoftware.ru/files/books/Delphi/Delphi5_DevelopersGuide_Volume_1(rus).pdf

Там есть про синтаксис языка Delphi и про то как объявлять деструктор (и что это вообще такое) там тоже есть.


 
4ort   (2008-04-16 13:21) [8]

ну даже если я объявлю его так ..

Destructor  Destroy; override;

что  толку - все равно уничтожение A и B - не работает, а вот если их (уничтожение A и B) заккомментить - то все ок...но компоненты то остаются


 
Kolan ©   (2008-04-16 13:23) [9]

> ну даже если я объявлю его так &#133

То что ты накатал в [0] говорит о том, что ты нихрена не понимаешь что делаешь&#133


> все равно уничтожение A и B — не работает

Это как ты узнал что оно не работает?


 
Сергей М. ©   (2008-04-16 13:23) [10]


> вот если их (уничтожение A и B


А ты их создавал, прежде чем пытаться их уничтожать ?


 
Dennis I. Komarov ©   (2008-04-16 13:25) [11]

> [8] 4ort   (16.04.08 13:21)

О компонентах пока речи вообще нет. У тебя класс, даже не наследуемый.
Давай так:
1. Почитать как надо
2. Сделать как понял из прочитанного
3. Сюда с вопросами


 
Kolan ©   (2008-04-16 13:25) [12]

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

Это как?


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

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


 
Kolan ©   (2008-04-16 13:27) [14]

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

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

Показывай как создавал&#133


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

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

TMyClass = class

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

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

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


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

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

TMyClass = class из [0]

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


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

конструктор:
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;


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


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


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

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


 
Dennis I. Komarov ©   (2008-04-16 13:30) [19]

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

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


 
Kolan ©   (2008-04-16 13:31) [20]

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

См. [15].

[1]
B : TImage;

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

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


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

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

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


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

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


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

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

 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;


 
Kolan ©   (2008-04-16 13:35) [24]

> destructor TMyClass.Free;

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


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

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

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;


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


> 4ort


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


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

Kolan ©   (16.04.08 13:35) [24]

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


 
Kolan ©   (2008-04-16 13:39) [28]

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

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


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

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


 
Dennis I. Komarov ©   (2008-04-16 13:40) [30]

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

Не-а


 
Kolan ©   (2008-04-16 13:41) [31]

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


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

TMyClass = class
 A : TLabel; {<-&#151; Про инкапсуляцию молчу. И про то, что все в published тоже.}
 B : TImage;
 constructor Create (Parent : TWinControl);
 destructor Destroy; override;
end;


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


> Kolan ©   (16.04.08 13:39) [28]
> > вот конструкор
>
> Что ты знаешь про фреймы ? :)


не понял вопроса....


 
Kolan ©   (2008-04-16 13:41) [33]

> интерпритатор

В Delphi есть компилятор.


 
Kolan ©   (2008-04-16 13:42) [34]

> не понял вопроса&#133

Про TFrame прочитай (срочно). :)


 
Сергей М. ©   (2008-04-16 13:42) [35]


> непредставляю что имеется ввиду под отладчиком


Дык возьми да впочитай про него в справке, в чем проблема ?


> если это про интерпритатор


Какой такой "интерпритатор" ?


> молчит как партизан


Ты у него не спрашиваешь, вот он и молчит)
С какого перепугу он должен тебе сам все рассказать да показать ?)


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

блин что неправильного тут ??

TMyClass = class
  A : TLabel;
  B : TImage;
  constructor Create (Parent : TWinControl);
  destructor Destroy; override;
end;


 
Kolan ©   (2008-04-16 13:44) [37]

> блин что неправильного тут ??

Кроме того, что ты поместил все в published секции все более мение.


 
Сергей М. ©   (2008-04-16 13:45) [38]


> что неправильного тут ?


По кр.мере, неправильно отсутствие спецификаторов области видимости объявляемых тобой идентификаторов.

Читай про private, protected, public, published


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

Kolan ©   (16.04.08 13:44) [37]

ну это дело поправимое - мне просто интересно - почему Label"ы не уничтожаются ...


 
umbra ©   (2008-04-16 13:46) [40]

2 4ort

Нельзя называть деструктор Free
Назовите его Destroy :) И скажите, что случится после этого.



Страницы: 1 2 вся ветка

Форум: "Начинающим";
Текущий архив: 2008.05.18;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.56 MB
Время: 0.044 c
15-1207069375
TIF
2008-04-01 21:02
2008.05.18
1 апреля - ФИНАЛ БЛИЗОК... Включите "Время" на Первом


15-1207390437
@!!ex
2008-04-05 14:13
2008.05.18
Программирование под Mac OS X


2-1208872290
@!!ex_
2008-04-22 17:51
2008.05.18
Как задать число в двоичной системе исчисления?


11-1189437864
Robt
2007-09-10 19:24
2008.05.18
PList


15-1207574311
Дмитрий С
2008-04-07 17:18
2008.05.18
Свой протокол для IE





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский