Commit e27ef43005d2d6d43a0b73348c3cdd4f4d21d2a6

Authored by Carlos Picanco
1 parent 10ea3650
Exists in master

fix empty contingencies on ini file

Showing 1 changed file with 95 additions and 82 deletions   Show diff stats
experiment_designer/form_main.pas
... ... @@ -1480,52 +1480,56 @@ procedure TFormDesigner.EditContingencyNameEditingDone(Sender: TObject);
1480 1480 var
1481 1481 LS, LC: string;
1482 1482 begin
1483   - with FExperiment do
1484   - if ComboCurrentContingency.ItemIndex <> -1 then
1485   - begin
1486   - LS := SEC_CONDITION+IntToStr(ComboCurrentCondition.ItemIndex+1);
1487   - LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
1488   - WriteString(LS, LC+ KEY_CONT_NAME, EditContingencyName.Text);
1489   - ComboCurrentContingency.Items[ComboCurrentContingency.ItemIndex] :=
1490   - LC + '|' + EditContingencyName.Text;
1491   - UpdateContingencyList(LS);
1492   - end;
  1483 + if RGContingencyType.ItemIndex > -1 then
  1484 + with FExperiment do
  1485 + if ComboCurrentContingency.ItemIndex <> -1 then
  1486 + begin
  1487 + LS := SEC_CONDITION+IntToStr(ComboCurrentCondition.ItemIndex+1);
  1488 + LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
  1489 + WriteString(LS, LC+ KEY_CONT_NAME, EditContingencyName.Text);
  1490 + ComboCurrentContingency.Items[ComboCurrentContingency.ItemIndex] :=
  1491 + LC + '|' + EditContingencyName.Text;
  1492 + UpdateContingencyList(LS);
  1493 + end;
1493 1494 end;
1494 1495  
1495 1496 procedure TFormDesigner.EditMessDone(Sender: TObject);
1496 1497 var
1497 1498 LSection, LContingency: String;
1498 1499 begin
1499   - LSection := SEC_CONDITION+IntToStr(ComboCurrentCondition.ItemIndex+1);
1500   - LContingency := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
  1500 + if RGContingencyType.ItemIndex > -1 then
  1501 + begin
  1502 + LSection := SEC_CONDITION+IntToStr(ComboCurrentCondition.ItemIndex+1);
  1503 + LContingency := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
1501 1504  
1502   - if Sender is TEdit then
1503   - with FExperiment do
1504   - begin
1505   - if TEdit(Sender) = EditMessPrefix then
1506   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_PREPEND, EditMessPrefix.Text);
  1505 + if Sender is TEdit then
  1506 + with FExperiment do
  1507 + begin
  1508 + if TEdit(Sender) = EditMessPrefix then
  1509 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_PREPEND, EditMessPrefix.Text);
1507 1510  
1508   - if TEdit(Sender) = EditMessPrefixLoss then
1509   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_PREPEND_LOSS,EditMessPrefixLoss.Text);
  1511 + if TEdit(Sender) = EditMessPrefixLoss then
  1512 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_PREPEND_LOSS,EditMessPrefixLoss.Text);
1510 1513  
1511   - if TEdit(Sender) = EditMessSufixLossSingular then
1512   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_LOSS_S,EditMessSufixLossSingular.Text);
  1514 + if TEdit(Sender) = EditMessSufixLossSingular then
  1515 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_LOSS_S,EditMessSufixLossSingular.Text);
1513 1516  
1514   - if TEdit(Sender) = EditMessSufixLossPlural then
1515   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_LOSS_P,EditMessSufixLossPlural.Text);
  1517 + if TEdit(Sender) = EditMessSufixLossPlural then
  1518 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_LOSS_P,EditMessSufixLossPlural.Text);
1516 1519  
1517   - if TEdit(Sender) = EditMessPrefixEarn then
1518   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_PREPEND_EARN,EditMessPrefixEarn.Text);
  1520 + if TEdit(Sender) = EditMessPrefixEarn then
  1521 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_PREPEND_EARN,EditMessPrefixEarn.Text);
1519 1522  
1520   - if TEdit(Sender) = EditMessSufixEarnSingular then
1521   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_EARN_S,EditMessSufixEarnSingular.Text);
  1523 + if TEdit(Sender) = EditMessSufixEarnSingular then
  1524 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_EARN_S,EditMessSufixEarnSingular.Text);
1522 1525  
1523   - if TEdit(Sender) = EditMessSufixEarnPlural then
1524   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_EARN_P,EditMessSufixEarnPlural.Text);
  1526 + if TEdit(Sender) = EditMessSufixEarnPlural then
  1527 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_EARN_P,EditMessSufixEarnPlural.Text);
1525 1528  
1526   - if TEdit(Sender) = EditMessSufixZero then
1527   - WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_ZERO, EditMessSufixZero.Text);
1528   - end;
  1529 + if TEdit(Sender) = EditMessSufixZero then
  1530 + WriteString(LSection, LContingency + KEY_CONSEQUE_MESSAGE_APPEND_ZERO, EditMessSufixZero.Text);
  1531 + end;
  1532 + end;
1529 1533 end;
1530 1534  
1531 1535 procedure TFormDesigner.ConsequenceMessageEditingDone(Sender: TObject);
... ... @@ -1628,14 +1632,17 @@ var
1628 1632 LS, LC : string;
1629 1633  
1630 1634 begin
1631   - LS := ExtractDelimited(1,ComboCurrentCondition.Items[ComboCurrentCondition.ItemIndex],['|']);
1632   - LC := GetContingencyName(RGContingencyType.ItemIndex = 1);
1633   - i := ComboCurrentContingency.Items.Add('');
1634   - ComboCurrentContingency.Items[i] :=
1635   - LC + '|' + EditContingencyName.Text;
1636   - ComboCurrentContingency.ItemIndex := i;
1637   - SaveContingency(LS,LC);
1638   - UpdateContingencyList(LS);
  1635 + if RGContingencyType.ItemIndex > -1 then
  1636 + begin
  1637 + LS := ExtractDelimited(1,ComboCurrentCondition.Items[ComboCurrentCondition.ItemIndex],['|']);
  1638 + LC := GetContingencyName(RGContingencyType.ItemIndex = 1);
  1639 + i := ComboCurrentContingency.Items.Add('');
  1640 + ComboCurrentContingency.Items[i] :=
  1641 + LC + '|' + EditContingencyName.Text;
  1642 + ComboCurrentContingency.ItemIndex := i;
  1643 + SaveContingency(LS,LC);
  1644 + UpdateContingencyList(LS);
  1645 + end;
1639 1646 end;
1640 1647  
1641 1648 procedure TFormDesigner.BtnRemoveCondClick(Sender: TObject);
... ... @@ -1746,35 +1753,36 @@ var
1746 1753 end;
1747 1754  
1748 1755 begin
1749   - if ComboCurrentContingency.ItemIndex > -1 then
1750   - begin
1751   - i := ComboCurrentContingency.ItemIndex;
1752   - MustReorder := i < ComboCurrentContingency.Items.Count - 1;
1753   - LS := ExtractDelimited(1, ComboCurrentCondition.Text, ['|']);
1754   - LC := ExtractDelimited(1, ComboCurrentContingency.Text, ['|']);
1755   - EraseContingency(LS,LC);
1756   - ComboCurrentContingency.Items.Delete(i);
1757   -
1758   - if MustReorder then
1759   - Reorder(i);
1760   -
1761   - case ComboCurrentContingency.Items.Count of
1762   - 0: {do nothing};
1763   - 1..MaxInt:
1764   - if i = 0 then
1765   - ComboCurrentContingency.ItemIndex := i
1766   - else
1767   - ComboCurrentContingency.ItemIndex := i -1;
  1756 + if RGContingencyType.ItemIndex > -1 then
  1757 + if ComboCurrentContingency.ItemIndex > -1 then
  1758 + begin
  1759 + i := ComboCurrentContingency.ItemIndex;
  1760 + MustReorder := i < ComboCurrentContingency.Items.Count - 1;
  1761 + LS := ExtractDelimited(1, ComboCurrentCondition.Text, ['|']);
  1762 + LC := ExtractDelimited(1, ComboCurrentContingency.Text, ['|']);
  1763 + EraseContingency(LS,LC);
  1764 + ComboCurrentContingency.Items.Delete(i);
  1765 +
  1766 + if MustReorder then
  1767 + Reorder(i);
  1768 +
  1769 + case ComboCurrentContingency.Items.Count of
  1770 + 0: {do nothing};
  1771 + 1..MaxInt:
  1772 + if i = 0 then
  1773 + ComboCurrentContingency.ItemIndex := i
  1774 + else
  1775 + ComboCurrentContingency.ItemIndex := i -1;
  1776 + end;
  1777 + UpdateContingencyList(LS);
  1778 + if ComboCurrentContingency.Items.Count > 0 then
  1779 + if (ComboCurrentContingency.ItemIndex > -1) and
  1780 + (ComboCurrentContingency.ItemIndex < ComboCurrentContingency.Items.Count) then
  1781 + begin
  1782 + LC := ExtractDelimited(1, ComboCurrentContingency.Text, ['|']);
  1783 + LoadContingency(LS,LC);
  1784 + end;
1768 1785 end;
1769   - UpdateContingencyList(LS);
1770   - if ComboCurrentContingency.Items.Count > 0 then
1771   - if (ComboCurrentContingency.ItemIndex > -1) and
1772   - (ComboCurrentContingency.ItemIndex < ComboCurrentContingency.Items.Count) then
1773   - begin
1774   - LC := ExtractDelimited(1, ComboCurrentContingency.Text, ['|']);
1775   - LoadContingency(LS,LC);
1776   - end;
1777   - end;
1778 1786 end;
1779 1787  
1780 1788 procedure TFormDesigner.BtnReorderCondClick(Sender: TObject);
... ... @@ -1926,9 +1934,12 @@ procedure TFormDesigner.ConsequenceStyleChange(Sender: TObject);
1926 1934 var
1927 1935 LS, LC: String;
1928 1936 begin
1929   - LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
1930   - LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
1931   - FExperiment.WriteString(LS, LC+KEY_CONSEQUE, GetConsequenceStyle);
  1937 + if RGContingencyType.ItemIndex > -1 then
  1938 + begin
  1939 + LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
  1940 + LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
  1941 + FExperiment.WriteString(LS, LC+KEY_CONSEQUE, GetConsequenceStyle);
  1942 + end;
1932 1943 end;
1933 1944  
1934 1945 procedure TFormDesigner.CGQuestionItemClick(Sender: TObject; Index: integer);
... ... @@ -1973,19 +1984,21 @@ var
1973 1984 end;
1974 1985  
1975 1986 begin
1976   - LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
1977   - LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
1978   - with FExperiment do
1979   - WriteString(LS, LC + KEY_CRITERIA, GetContingencyCriteria);
1980   -
1981   - if TCheckBox(Sender).Name = 'ChkEqual' then
1982   - if TCheckBox(Sender).Checked then
1983   - UncheckBox('ChkDiff');
  1987 + if RGContingencyType.ItemIndex > -1 then
  1988 + begin
  1989 + LS := ExtractDelimited(1,ComboCurrentCondition.Text,['|']);
  1990 + LC := ExtractDelimited(1,ComboCurrentContingency.Text,['|']);
  1991 + with FExperiment do
  1992 + WriteString(LS, LC + KEY_CRITERIA, GetContingencyCriteria);
1984 1993  
1985   - if TCheckBox(Sender).Name = 'ChkDiff' then
1986   - if TCheckBox(Sender).Checked then
1987   - UncheckBox('ChkEqual');
  1994 + if TCheckBox(Sender).Name = 'ChkEqual' then
  1995 + if TCheckBox(Sender).Checked then
  1996 + UncheckBox('ChkDiff');
1988 1997  
  1998 + if TCheckBox(Sender).Name = 'ChkDiff' then
  1999 + if TCheckBox(Sender).Checked then
  2000 + UncheckBox('ChkEqual');
  2001 + end;
1989 2002 end;
1990 2003  
1991 2004 // TODO: hidden persistence.xml on windows
... ...