![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Property
9899100 © (2008-12-16 13:34:00)Подскажите плииз
запутался :)
есть класс
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;
9899100 (2008-12-16 13:45:00) [1]
> Ega23 ©
точно, спасибо, чейто я не подумал про проверку индекса на интервал
Ega23 (2008-12-16 13:43:00) [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:00) [3]>>Сергей М
шайтан
может она сама и все остальное напишет :))))))))))))
Сергей М. (2008-12-16 13:38:00) [4]property Use[Index:Integer]:Boolean read ReadUse write WriteUse;
Теперь ставишь курсор ввода на декларацию своего класса, жмешь CTRL-SHIFT-C и - о чудо ! - Делфи сама нарисовала все что тебе нужно)