Другие языки программирования и технологии
А можно ли сократить данный код?
procedure TForm2.RadioGroup7Click(Sender: TObject); begin if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=2.8; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=3.7; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=3.3; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=4.3; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=1) and (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=5) and (RadioGroup7.ItemIndex=0) then a:=20.7; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=0) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=1) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=1; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=0) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=0.7; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=6) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=1) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=5.4; if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=6) and (RadioGroup4.ItemIndex=0) and (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=3.8; end;
например, так
if (RadioGroup1.ItemIndex=0) then
if (RadioGroup4.ItemIndex=1) and (RadioGroup7.ItemIndex=0) then begin
if (RadioGroup2.ItemIndex=5) and (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=5) then a:=20.7 end
else
if (RadioGroup4.ItemIndex=0) and (RadioGroup7.ItemIndex=3) then
if (RadioGroup2.ItemIndex=0) and (RadioGroup6.ItemIndex=4) then begin
if (RadioGroup5.ItemIndex=1) then a:=1 else if (RadioGroup5.ItemIndex=2) then a:=0.7 end
else
if (RadioGroup2.ItemIndex=6) and (RadioGroup6.ItemIndex=7) then begin
if (RadioGroup5.ItemIndex=1) then a:=5.4else if (RadioGroup5.ItemIndex=2) then a:=3.8 end
else
if (RadioGroup2.ItemIndex=5) and (RadioGroup5.ItemIndex=2) then begin
if (RadioGroup6.ItemIndex=4) then a:=3.3 else if (RadioGroup6.ItemIndex=7) then a:=4.3 end
else
if (RadioGroup2.ItemIndex=5) and (RadioGroup5.ItemIndex=0) then begin
if (RadioGroup6.ItemIndex=4) then a:=2.8 else if (RadioGroup6.ItemIndex=7) then a:=3.7 end;
если еще исключить проверки, которые не могут выполняться в принципе, то можно еще немало сократить
if (RadioGroup1.ItemIndex=0) then
if (RadioGroup4.ItemIndex=1) and (RadioGroup7.ItemIndex=0) then begin
if (RadioGroup2.ItemIndex=5) and (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=5) then a:=20.7 end
else
if (RadioGroup4.ItemIndex=0) and (RadioGroup7.ItemIndex=3) then
if (RadioGroup2.ItemIndex=0) and (RadioGroup6.ItemIndex=4) then begin
if (RadioGroup5.ItemIndex=1) then a:=1 else if (RadioGroup5.ItemIndex=2) then a:=0.7 end
else
if (RadioGroup2.ItemIndex=6) and (RadioGroup6.ItemIndex=7) then begin
if (RadioGroup5.ItemIndex=1) then a:=5.4else if (RadioGroup5.ItemIndex=2) then a:=3.8 end
else
if (RadioGroup2.ItemIndex=5) and (RadioGroup5.ItemIndex=2) then begin
if (RadioGroup6.ItemIndex=4) then a:=3.3 else if (RadioGroup6.ItemIndex=7) then a:=4.3 end
else
if (RadioGroup2.ItemIndex=5) and (RadioGroup5.ItemIndex=0) then begin
if (RadioGroup6.ItemIndex=4) then a:=2.8 else if (RadioGroup6.ItemIndex=7) then a:=3.7 end;
если еще исключить проверки, которые не могут выполняться в принципе, то можно еще немало сократить
Можно попробовать так
procedure TForm2.RadioGroup7Click(Sender: TObject);
begin
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=0) then
begin
if (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=2.8;
if (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=3.7;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=3.3;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=4.3;
end;
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=1) then
if (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=5) and (RadioGroup7.ItemIndex=0) then a:=20.7;
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=0) and (RadioGroup4.ItemIndex=0) then
begin
if (RadioGroup5.ItemIndex=1) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=1;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=0.7;
end;
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=6) and (RadioGroup4.ItemIndex=0) then
begin
if (RadioGroup5.ItemIndex=1) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=5.4;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=3.8;
end;
end.
procedure TForm2.RadioGroup7Click(Sender: TObject);
begin
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=0) then
begin
if (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=2.8;
if (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=3.7;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=3.3;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=4.3;
end;
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=5) and (RadioGroup4.ItemIndex=1) then
if (RadioGroup5.ItemIndex=0) and (RadioGroup6.ItemIndex=5) and (RadioGroup7.ItemIndex=0) then a:=20.7;
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=0) and (RadioGroup4.ItemIndex=0) then
begin
if (RadioGroup5.ItemIndex=1) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=1;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=4) and (RadioGroup7.ItemIndex=3) then a:=0.7;
end;
if (RadioGroup1.ItemIndex=0) and (RadioGroup2.ItemIndex=6) and (RadioGroup4.ItemIndex=0) then
begin
if (RadioGroup5.ItemIndex=1) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=5.4;
if (RadioGroup5.ItemIndex=2) and (RadioGroup6.ItemIndex=7) and (RadioGroup7.ItemIndex=3) then a:=3.8;
end;
end.
обратите внимание: ответ исправлен. порядок составления x изменен на обратный
x := RadioGroup1.ItemIndex;
x := 10*x+RadioGroup2.ItemIndex;
x := 10*x+RadioGroup4.ItemIndex;
x := 10*x+RadioGroup5.ItemIndex
x := 10*x+RadioGroup6.ItemIndex;
x := 10*x+RadioGroup7.ItemIndex;
case (x) of
050043: a:=2.8;
050073: a:=3.7;
...
end
x := RadioGroup1.ItemIndex;
x := 10*x+RadioGroup2.ItemIndex;
x := 10*x+RadioGroup4.ItemIndex;
x := 10*x+RadioGroup5.ItemIndex
x := 10*x+RadioGroup6.ItemIndex;
x := 10*x+RadioGroup7.ItemIndex;
case (x) of
050043: a:=2.8;
050073: a:=3.7;
...
end
Разве нельзя для каждой радиогруппы ввести коэфициент и умножать на него при событии от переключения?
Вполне возможно
не можно, а нужно
Можно.
Я в этои не очень но всем кто разбирается НАХ ЕМУ ВАШИ ДА НЕТ СОКРОТИТЕ И НАПИШИТЕ
Нет.
думаю что можно
Похожие вопросы
- С++ Можете объяснить принцип работы данного кода?
- Всем доброго времени суток, я хотел бы узнать о контейнере map. Что он выполняет в данном коде? Заранее спасибо.
- как можно сократить этот js код?
- Вопрос по основам машинного кода и бинарного кода. Как это работает в своей основе?
- Ассемблерная вставка в С .Странный код. Можете расшифровать?
- как прописать bat код в сайт
- Что для вас "говно код" ?
- как научиться писать хороший код? В смысле я даже не понимаю что такое хороший код. Что такое хороший код?
- ООП это когда данные управляют кодом а функциональное когда код данными?
- Получение опыта в области программирования (архитектура программы, качество кода).