![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
|
|
#1
|
|||
|
|||
|
доброго времени суток!
вобщем такой вопрос, как объединить объекты в одно чтонибудь, чтоб можно было к ним всем обращатся как к одному объекту по индексу? уже не первый день бъюсь, ничо не помогает, пытался и в массив, и в список.. все либо компилятор ругаетсо, либо прога падает (так все работает, но и новичку видно что код топорный, ибо видно что одна процедура по 10 раз повторяется с различием в номер объекта) Код:
procedure TForm1.DrawIconFile;
var
x: string;
o, i, b: integer;
begin
//присвоение иконки файла к комбобоксуЕх по его расширению
ComboBoxEx1.ItemIndex := 0;
b:=0;
o:=0;
for I := 0 to ComboBoxEx1.ItemsEx.Count - 1 do begin
x:=copy(ComboBoxEx1.Items[ComboBoxEx1.ItemIndex+ b],length(ComboBoxEx1.Items[ComboBoxEx1.ItemIndex+ b])-3,
length(ComboBoxEx1.Items[ComboBoxEx1.ItemIndex+ b]));
if x = '.doc' then o := 3;
if x = 'docx' then o := 0;
if x = '.xls' then o := 2;
if x = 'xlsx' then o := 1;
ComboBoxEx1.ItemsEx[ComboBoxEx1.ItemIndex+ b].ImageIndex := o;
b:= b + 1;
end;
//и вот тут по новой для второго...
ComboBoxEx2.ItemIndex := 0;
b:=0;
o:=0;
for I := 0 to ComboBoxEx2.ItemsEx.Count - 1 do begin
x:=copy(ComboBoxEx2.Items[ComboBoxEx2.ItemIndex+ b],length(ComboBoxEx2.Items[ComboBoxEx2.ItemIndex+ b])-3,
length(ComboBoxEx2.Items[ComboBoxEx2.ItemIndex+ b]));
if x = '.doc' then o := 3;
if x = 'docx' then o := 0;
if x = '.xls' then o := 2;
if x = 'xlsx' then o := 1;
ComboBoxEx2.ItemsEx[ComboBoxEx2.ItemIndex+ b].ImageIndex := o;
b:= b + 1;
end;
//и для 3го...
ComboBoxEx3.ItemInd....
//как избежать этих глупых повторений и грамотно объединить их во чтото одно и обращатся по индексу? |
|
#2
|
||||
|
||||
|
попробуй FindComponent:
Код:
for i:= 1 to 3 do
begin
(FindComponent('ComboBoxEx' + IntToStr(i)) as TComboBoxEx).ItemIndex:= 0;
и так далее...
end; |
|
#3
|
||||
|
||||
|
Можно использовать список:
Код:
var
L : TList;
procedure TForm1.FormCreate(Sender: TObject);
begin
L := TList.Create;
L.Add(ComboBox1);
L.Add(ComboBox2);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
L.Free;
end;
procedure TForm1.DrawIconFile;
var
x: string;
o, i, k, b, id: integer;
cb:TComboBox;
begin
for k:=0 to L.Count-1 do
begin
cb := (TObject(L.Items[k]) as TComboBox);
cb.ItemIndex := 0;
b := 0;
o := 0;
for i:=0 to cb.ItemsEx.Count-1 do
begin
id := cb.ItemIndex + b;
x:=copy(cb.Items[id],length(cb.Items[id])-3,length(cb.Items[id]));
if x = '.doc' then o := 3
else if x = 'docx' then o := 0
else if x = '.xls' then o := 2
else if x = 'xlsx' then o := 1;
cb.ItemsEx[id].ImageIndex := o;
Inc(b);
end;
end;
end; |
|
#4
|
|||
|
|||
|
2 Rokuell огромное спасибо! самому не получалось все в список загнать чтоб работало...
|
|
#5
|
|||
|
|||
|
сорри за глупость.. но возможно этот код ужать до такогоже списка..?
Код:
procedure TForm1.SearchCounDocs;
Var
SearchRec:TSearchRec;
begin
If FindFirst((ExtractFilePath(paramstr(0)) + 'Docs\230101\Konsp\*.' + SearchRasch),
faAnyFile, SearchRec)=0 then //конспекты
repeat
if (SearchRasch = 'doc') or (SearchRasch = 'xls') then
if (copy(SearchRec.name,length(SearchRec.name)-3,length(SearchRec.name)) <> 'docx')
or (copy(SearchRec.name,length(SearchRec.name)-3,length(SearchRec.name)) <> 'xlsx')
then
ComboBoxEx7.Items.Add(SearchRec.name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
If FindFirst((ExtractFilePath(paramstr(0)) + 'Docs\230101\Video\*.' + SearchRasch),
faAnyFile, SearchRec)=0 then //видео
repeat
if (SearchRasch = 'doc') or (SearchRasch = 'xls') then
if (copy(SearchRec.name,length(SearchRec.name)-3,length(SearchRec.name)) <> 'docx')
or (copy(SearchRec.name,length(SearchRec.name)-3,length(SearchRec.name)) <> 'xlsx')
then
ComboBoxEx6.Items.Add(SearchRec.name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
......неподдаются эти списки мне... ![]() |
|
#6
|
||||
|
||||
|
Напиши одну процедуру с переменными параметрами и используй ее, например так:
Код:
procedure gg(s: string; ComboBoxEx: TComboBoxEx);
Var
SearchRec:TSearchRec;
begin
If FindFirst((ExtractFilePath(paramstr(0)) + 'Docs\230101\' + s + '\*.' + SearchRasch),
faAnyFile, SearchRec)=0 then
repeat
if (SearchRasch = 'doc') or (SearchRasch = 'xls') then
if (copy(SearchRec.name,length(SearchRec.name)-3,length(SearchRec.name)) <> 'docx')
or (copy(SearchRec.name,length(SearchRec.name)-3,length(SearchRec.name)) <> 'xlsx')
then
ComboBoxEx.Items.Add(SearchRec.name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
procedure TForm1.SearchCounDocs;
begin
gg('Konsp', ComboBoxEx7);
gg('Video', ComboBoxEx6);
// ....
end; |