Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Problema con TMonthCalendar (https://www.clubdelphi.com/foros/showthread.php?t=90473)

Angel.Matilla 17-06-2016 13:14:51

Problema con TMonthCalendar
 

Tengo el formulario que se ve en la imagen. Antes de pinchar en el TRadioGroup inferior hay que seleccionar la fecha de cargo.

Tengo este código.
- En el OnCreate del formulario
Código:

void __fastcall TfGenRec::FormCreate(TObject *Sender)
{
    Button1->Enabled    = false;
    GroupBox1->Visible  = false;
    RadioGroup1->Enabled = false;

    F_cargo->MinDate = Date();
    while (F_cargo->MinDate.DayOfWeek() == 1 || F_cargo->MinDate.DayOfWeek() == 7)
          F_cargo->MinDate ++;

    nItem = 0;
    F_cargo->Date    = F_cargo->MinDate;
    F_cargo->MaxDate = F_cargo->MinDate;
    while (nItem < 3)
    {
          F_cargo->MaxDate ++;
          if (F_cargo->MaxDate.DayOfWeek() == 1 || F_cargo->MaxDate.DayOfWeek() == 7)
              continue;

          nItem ++;
    }

}
//---------------------------------------------------------------------------

- En el OnPaint del formulario:
Código:

void __fastcall TfGenRec::FormPaint(TObject *Sender)
{
    F_cargo->Enabled = true;
    F_cargo->Date    = F_cargo->MinDate;
    F_cargo->SetFocus();
}
//---------------------------------------------------------------------------

- En OnKeyPress del formulario:
Código:

void __fastcall TfGenRec::FormKeyPress(TObject *Sender, char &Key)
{
    if (Key == 27)
    {
          Key = 0;
          Button2Click(NULL);
          return;
    }
}
//---------------------------------------------------------------------------

- En OnClick del Button2:
Código:

void __fastcall TfGenRec::Button2Click(TObject *Sender)
{
    if (!F_cargo->Enabled)
          FormCreate(NULL);
    else
          this->Close();
    return;
}
//---------------------------------------------------------------------------

- En OnClick del TMonthCalendar:
Código:

void __fastcall TfGenRec::F_cargoClick(TObject *Sender)
{
    if (F_cargo->Date.DayOfWeek() == 1 || F_cargo->Date.DayOfWeek() == 7)
    {
          Mensaje(1, "FECHA DE CARGO: " + F_cargo->Date.FormatString("dd/mm/yyyy") + "\n\nNo puede facturarse en días bancarios inhábiles.", "Volver");
          F_cargo->Date    = Date();
          F_cargo->SetFocus();
          return;
    }

    if (Mensaje(2, "Ha seleccionado como fecha de cargo: " + F_cargo->Date.FormatString("dd/mm/yyyy"), "La fecha es correcta\nModificar fecha") == 2)
    {
          F_cargo->SetFocus();
          return;
    }

    F_cargo->Enabled      = false;
    RadioGroup1->ItemIndex = -1;
    RadioGroup1-Enabled    = true;
    RadioGroup1->SetFocus();
}
//---------------------------------------------------------------------------

El problema es que si ya está habilitado el TRadioGroup y pulso ESC o hago click en el botón Cancelar, pulse donde pulse del calendario no me modifica la fecha y SÓLO me selecciona la fecha mínima, que suele ser la del día del sistema.
Todas las variables que hay por el código (nItem por ejemplo) y funciones (Mensaje(...)) están definidas.

escafandra 22-06-2016 00:53:04

No utilices el operador ++ con propiedades, evitarás problemas incomprensibles (las propiedades vienen de delphi)

Código:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    F_cargo->Enabled    = true;
    Button1->Enabled    = false;
    // GroupBox1->Visible  = false;
    RadioGroup1->Enabled = false;

    F_cargo->MinDate = Date();
    F_cargo->MaxDate = F_cargo->MinDate;

    while (F_cargo->MinDate.DayOfWeek() == 1 || F_cargo->MinDate.DayOfWeek() == 7)
          F_cargo->MinDate = F_cargo->MinDate + 1;

    int nItem = 0;
    F_cargo->Date    = F_cargo->MinDate;
    F_cargo->MaxDate = F_cargo->MinDate;
    while (nItem < 3)
    {
          F_cargo->MaxDate = F_cargo->MaxDate + 1;
          if (F_cargo->MaxDate.DayOfWeek() == 1 || F_cargo->MaxDate.DayOfWeek() == 7)
              continue;

          nItem ++;
    }
}


Saludos.

Angel.Matilla 22-06-2016 09:56:32

Haré la prueba y ya comento.


La franja horaria es GMT +2. Ahora son las 23:11:42.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi