Вниз
Скачать: CL | DM;

Property   Найти похожие ветки 

← →
9899100   (2008-12-16 13:34) [0]

Подскажите плииз
запутался :)
есть класс
TMyClass=class
  fUse:Array[1..10] of Boolean;
 
  function ReadUse(Index:Integer):Boolean;
 
 public
   ....
  property Use[Index:Integer]:Boolean read ReadUse;
end;

Function TMyClass.ReadUse;
Begin
result:=fUse[Index];
End;

таким образом можно читать из этого свойства
а как должна выглядеть процедура записи
чтобы можно было в экземпляре класса
написать

ttt.Use[2]:=True;


← →
Сергей М. ©   (2008-12-16 13:38) [1]

property Use[Index:Integer]:Boolean read ReadUse write WriteUse;

Теперь ставишь курсор ввода на декларацию своего класса, жмешь CTRL-SHIFT-C и - о чудо ! - Делфи сама нарисовала все что тебе нужно)


← →
Ega23 ©   (2008-12-16 13:43) [2]

TMyClass=class
private
 fUse:Array[1..10] of Boolean;

 function GetItem(Index: Integer): Boolean;
 procedure SetItem(Index: Integer; const Value: Boolean);
public
 property Items[Index:Integer] : Boolean read GetItem write SetItem; default;
end;

function TMyClass.GetItem(Index: Integer): Boolean;
begin
 if (Index<Low(fUse)) or (Index>High(fUse)) then
   raise Exception.Create("Index out of bounds");
 Result :=  fUse[Index];
end;

procedure TMyClass.SetItem(Index: Integer; const Value: Boolean);
begin
 if (Index<Low(fUse)) or (Index>High(fUse)) then
   raise Exception.Create("Index out of bounds");
 fUse[Index] := Value;
end;


← →
9899100   (2008-12-16 13:43) [3]

>>Сергей М
шайтан

может она сама и все остальное напишет :))))))))))))


← →
9899100   (2008-12-16 13:45) [4]


> Ega23 ©


точно, спасибо, чейто я не подумал про проверку индекса на интервал



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

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.009 c
2-1229413142
Мурзик
2008-12-16 10:39
2009.02.01
Ограничение на ввод


4-1204653401
misha_gr
2008-03-04 20:56
2009.02.01
SetScrollInfo и SetScrollPos не прокручивают текст внутри окна.


15-1227341190
Gydvin
2008-11-22 11:06
2009.02.01
Создание битмап в цветовом пространстве CMYK


2-1229374412
bit
2008-12-15 23:53
2009.02.01
TListView get item


3-1213861475
кот
2008-06-19 11:44
2009.02.01
не проходят запросы




   Наверх