bool __fastcall TCustomCommandOptionsDialog::Execute(TShortCut * ShortCut)
{
  if (ShortCut != NULL)
  {
    SetShortCutCombo(FShortCutCombo, *ShortCut);
  }

  bool Result = TCustomDialog::Execute();

  if (Result)
  {
    int ControlIndex = 0;
    for (int OptionIndex = 0; OptionIndex < FCommand->OptionsCount; OptionIndex++)
    {
      const TCustomCommandType::TOption & Option = FCommand->GetOption(OptionIndex);
      if ((Option.Flags & FFlags) != 0)
      {
        if ((Option.Kind != TCustomCommandType::okUnknown) &&
            Option.IsControl)
        {
          UnicodeString OptionKey = FCommand->GetOptionKey(Option, FSite);

          TControl * Control = FControls[ControlIndex];

          UnicodeString Value;
          if (Option.Kind == TCustomCommandType::okTextBox)
          {
            Value = SaveHistoryComboBoxValue(Control, Option);
          }
          else if (Option.Kind == TCustomCommandType::okFile)
          {
            Value = SaveHistoryComboBoxValue(Control, Option);
          }
          else if (Option.Kind == TCustomCommandType::okDropDownList)
          {
            Value = GetComboBoxValue(Control, Option.Default);
          }
          else if (Option.Kind == TCustomCommandType::okComboBox)
          {
            TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
            Value = GetComboBoxValue(Control, ComboBox->Text);
          }
          else if (Option.Kind == TCustomCommandType::okCheckBox)
          {
            TCheckBox * CheckBox = DebugNotNull(dynamic_cast<TCheckBox *>(Control));
            int Index = (CheckBox->Checked ? 0 : 1);
            Value = (Index < static_cast<int>(Option.Params.size())) ? Option.Params[Index] : UnicodeString();
          }
          else
          {
            DebugFail();
          }

          // The default value setter deletes the "name" when the value is empty.
          // It would cause us to fall back to the default value, but we want to remember the empty value.
          SetStringValueEvenIfEmpty(FCustomCommandOptions, OptionKey, Value);
        }

        ControlIndex++;
      }
    }

    if (ShortCut != NULL)
    {
      *ShortCut = GetShortCutCombo(FShortCutCombo);
    }
  }

  return Result;
}

bool __fastcall TCustomCommandOptionsDialog::Execute(TShortCut * ShortCut)
{
  if (ShortCut != NULL)
  {
    SetShortCutCombo(FShortCutCombo, *ShortCut);
  }

  bool Result = TCustomDialog::Execute();

  if (Result)
  {
    int ControlIndex = 0;
    for (int OptionIndex = 0; OptionIndex < FCommand->OptionsCount; OptionIndex++)
    {
      const TCustomCommandType::TOption & Option = FCommand->GetOption(OptionIndex);
      if ((Option.Flags & FFlags) != 0)
      {
        if ((Option.Kind != TCustomCommandType::okUnknown) &&
            Option.IsControl)
        {
          UnicodeString OptionKey = FCommand->GetOptionKey(Option, FSite);

          TControl * Control = FControls[ControlIndex];

          UnicodeString Value;
          if (Option.Kind == TCustomCommandType::okTextBox)
          {
            Value = SaveHistoryComboBoxValue(Control, Option);
          }
          else if (Option.Kind == TCustomCommandType::okFile)
          {
            Value = SaveHistoryComboBoxValue(Control, Option);
          }
          else if (Option.Kind == TCustomCommandType::okDropDownList)
          {
            Value = GetComboBoxValue(Control, Option.Default);
          }
          else if (Option.Kind == TCustomCommandType::okComboBox)
          {
            TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
            Value = GetComboBoxValue(Control, ComboBox->Text);
          }
          else if (Option.Kind == TCustomCommandType::okCheckBox)
          {
            TCheckBox * CheckBox = DebugNotNull(dynamic_cast<TCheckBox *>(Control));
            int Index = (CheckBox->Checked ? 0 : 1);
            Value = (Index < static_cast<int>(Option.Params.size())) ? Option.Params[Index] : UnicodeString();
          }
          else
          {
            DebugFail();
          }

           
           
          SetStringValueEvenIfEmpty(FCustomCommandOptions, OptionKey, Value);
        }

        ControlIndex++;
      }
    }

    if (ShortCut != NULL)
    {
      *ShortCut = GetShortCutCombo(FShortCutCombo);
    }
  }

  return Result;
}
