Другие языки программирования и технологии

А можно ли сократить данный код?

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;
HT
Homayoon Totakhil
654
например, так
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;
если еще исключить проверки, которые не могут выполняться в принципе, то можно еще немало сократить
ДК
Данияр Каисыков
19 025
Лучший ответ
Можно попробовать так
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
Разве нельзя для каждой радиогруппы ввести коэфициент и умножать на него при событии от переключения?
Вполне возможно
OA
Osman Apu
12 168
не можно, а нужно
Можно.
Сергей Агеев
Сергей Агеев
1 884
Я в этои не очень но всем кто разбирается НАХ ЕМУ ВАШИ ДА НЕТ СОКРОТИТЕ И НАПИШИТЕ
Ivan Zakryzhevskiy
Ivan Zakryzhevskiy
643
думаю что можно