Ver Mensaje Individual
  #4  
Antiguo 09-07-2015
tmsanchez tmsanchez is offline
Miembro
 
Registrado: mar 2004
Ubicación: Mexico
Posts: 67
Reputación: 21
tmsanchez Va por buen camino
HOla, no tengo delphi a la mano, pero ésta es una idea de cómo podría ser:

Guarda la información en un arreglo de dos dimensiones:

Código Delphi [-]
type
  TCalendarioMes = Array[1..7,1..5] of Integer;
var
  enero : TCalendarioMes;

procedure inicializaCalendario;
var
  i,j : Integer;
begin
  for i:= 1 to 7 do
    for j := 1 to 5 do
      enero[i,j] := 0;  // sin asignar
end;

procedure marcaAsignado(fila, columna: Integer);
begin
  enero[fila,columna] := 1;
end;

procedure desmarcaAsignado(fila, columna: Integer);
begin
  enero[fila,columna] := 0;
end;


Cuando selecciones la celda en el grid cambias el estado en el arreglo

Código Delphi [-]
procedure seleccionar_dia(X, Y: Integer;StrMes:TStringGrid);
var
  aCol, aRow :integer;
  p:TPoint;
begin
  with FrmCalendarioOficial do
  begin
    StrMes.MouseToCell(X, Y, aCol, aRow);      
    StrMes.Row := aRow;      
    StrMes.Col := aCol;
    marcaAsignado(aCol,aRow);          
    p := StrMes.ClientToScreen(Point(x,y));
    PopupMenu1.popup(p.x, p.y);
  end;
end;

procedure TFrmCalendarioOficial.StrEneroMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  aCol, aRow :integer;
  p:TPoint;
begin
  if button = mbright then
    seleccionar_dia( X, Y,StrEnero);
end;


Cuando verifiques si se tiene que resaltar consultas el arreglo

Código Delphi [-]
procedure TFrmCalendarioOficial.StrEneroDrawCell(Sender: TObject; aCol,   
  aRow: Integer; aRect: TRect; aState: TGridDrawState);
begin
  with TStringGrid(Sender) do
  begin
    if not (gdFixed in aState) then
    begin       // aqui puedes verificar si esta encendido o asignado
      if ((gdSelected in aState) and (Cells[Acol,Arow]<>'')) then
        Canvas.Brush.Color := clHighlight
      else
        Canvas.Brush.Color := clWindow;
      Canvas.FillRect(aRect);
    end;
  Canvas.TextRect(aRect, ACol, ARow, Cells[ACol, ARow]);
  end;
end;

Última edición por ecfisa fecha: 09-07-2015 a las 23:35:47. Razón: Corregir error WYSIWYG
Responder Con Cita