Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2009.03.29;
Скачать: CL | DM;

Вниз

Как правильно реализовать...   Найти похожие ветки 

 
НосокСудьбы   (2009-02-06 00:56) [0]

...свойство класса, которое по определению есть множество, содержащее экземпляры другого класса. Короче array of TSomeClass.


 
Германн ©   (2009-02-06 01:20) [1]

А нужно именно множество? Список не подойдёт?


 
Amoeba ©   (2009-02-06 02:20) [2]

Если число этих экземпляров может варьировать, то использовать св-то типа  TObjectList.


 
НосокСудьбы   (2009-02-06 08:15) [3]

Т.е. задача решается только с помощью создания дополнительного класса, наследника TObjectList?


 
ЮЮ ©   (2009-02-06 08:32) [4]


> свойство класса, которое по определению есть множество,
> содержащее экземпляры другого класса. Короче array of TSomeClass


А зачем реализацию выпячивать?
Почему не так?
 
property Count: integer read GetCount
property Item[AIndex: integer]:TSomeClass read GetItem write SetItem

а будет ли внутри класса array of TSomeClass или TObjectList будет зависеть от того, что лучше в конкретном случае.


 
НосокСудьбы   (2009-02-06 09:13) [5]


> ЮЮ ©   (06.02.09 08:32) [4]

А как бороться этим:
TSomeClass
 property Item[AIndex: integer]:TSome2Class read GetItem write SetItem
...
a := TSomeClass.Create;
a.Item[100].Cerate;


> Германн ©   (06.02.09 01:20) [1]
> А нужно именно множество? Список не подойдёт?

Хм...
Если я все правильно понял, то в данном контексте, это одно и тоже.


 
Palladin ©   (2009-02-06 09:15) [6]


> А как бороться этим:TSomeClass  property Item[AIndex: integer]:
> TSome2Class read GetItem write SetItem...a := TSomeClass.
> Create;a.Item[100].Cerate;

А что с "этим" не так?


 
Palladin ©   (2009-02-06 09:22) [7]

Вообще не понимаю в чем проблема

TSome2Class=Class
 Private
  d:Integer;
 Public
  Property Data:Integer Read d Write d;
End;

TSome2Classes=Class
 Private
  m_theItems:TList;

  Function lcGetCount:Integer;
  Function lcGetItem(p_nIndex:Integer):TSome2Class;
 Public
  Constructor Create;
  Destructor Destroy; Override;

  Property Count:Integer Read lcGetCount;
  Property Items[nIndex:Integer]:TSome2Class Read lcGetItem; Default;

  Function Add(p_theSome2:TSome2Class):Integer;
  Procedure Delete(p_nIndex:Integer);
  Procedure Clear;
End;

Constructor TSome2Classes.Create;
Begin
 m_theItems:=TList.Create;
End;

Destructor TSome2Classes.Destroy;
Begin
 Clear;
 m_theItems.Free;
End;

Function TSome2Classes.lcGetCount;
Begin
 Result:=m_theItems.Count;
End;

Function TSome2Classes.lcGetItem;
Begin
 Result:=TSome2Class(m_theItems[p_nIndex]);
End;

Function TSome2Classes.Add;
Begin
 Result:=m_theItems.Add(p_theSome2);
End;

Procedure TSome2Classes.Delete;
Begin
 Items[p_nIndex].Free;
 m_theItems.Delete(p_nIndex);
End;

Procedure TSome2Classes.Clear;
Var
 i:Integer;
Begin
 For i:=0 to Count-1 Do Items[i].Free;
 m_theItems.Clear;
End;


 
НосокСудьбы   (2009-02-06 09:22) [8]


> Palladin ©   (06.02.09 09:15) [6]
> А что с "этим" не так?

Может я чего не понимаю, но у меня на такой конструкции AV.


 
Palladin ©   (2009-02-06 09:26) [9]


> Может я чего не понимаю, но у меня на такой конструкции
> AV.

Естественно, она смысла не имеет. Если все таки нужно иметь возможность изменять элементы, то, приведенное выше мною, чуток меняется

Private
 Procedure lcSetItem(p_nIndex:Integer;p_theSome2:TSome2Class);

Property Items[nIndex:Integer]:TSome2Class Read lcGetItem Write lcSetItem; Default;

Procedure TSome2Classes.lcSetItem;
Begin
 Items[p_nIndex].Free; // если нужно уничтожить предыдущий объект
 m_theItems[p_nIndex]:=p_theSome2;
End;



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

Текущий архив: 2009.03.29;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.019 c
1-1208194778
gear
2008-04-14 21:39
2009.03.29
Локализация "на лету"


1-1208942275
carmen
2008-04-23 13:17
2009.03.29
эксторт в XML из ExpressQuantumGrid Suite 6.24


2-1234085225
jonin
2009-02-08 12:27
2009.03.29
текстовый файл


15-1232712297
Дополз
2009-01-23 15:04
2009.03.29
А может ли администрация сайта (любого) узнать...


1-1208202474
aha
2008-04-14 23:47
2009.03.29
Как можно выполнить такое ? Для сохранения параметров программы