Hola Newtron, muchas gracias por tu ayuda, seguramente lo que pasa es eso, de hecho cuando creo el checkbox le asigno en el tag el numero de la fila, el problema es que estoy asociando el evento onclic del checkbox a otro ya creado. y ahi se me pierde el numero.
bueno les explico como lo hice.
1. tengo un panel (panel1).
2. una stringgrid (stringgrid2)
3. un calendario (xxxx) //no me acuero por que le puse ese nombre...
4. un label para indicar la fecha (label18).
5. tengo un checkbox donde hago la actualizacion (checkbox3).
al darle click a un dia del calendario hago lo siguiente:
Código Delphi
[-]
procedure TForm3.XXXXClick(Sender: TObject);
var
x,i:Integer;
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
dia, mes: string;
begin
Present:= XXXX.date;
DecodeDate(Present, Year, Month, Day);
CASE DayOfTheWeek(XXXX.date) OF
1: DIA:='Lunes';
2: DIA:='Martes';
3: DIA:='Miercoles';
4: DIA:='Jueves';
5: DIA:='Viernes';
6: DIA:='Sabado';
7: DIA:='Domingo';
END;
case month of
1: mes := 'Enero';
2: mes := 'Febrero';
3: mes := 'Marzo';
4: mes := 'Abril';
5: mes := 'Mayo';
6: mes := 'Junio';
7: mes := 'Julio';
8: mes := 'Agosto';
9: mes := 'Septiembre';
10: mes := 'Octubre';
11: mes := 'Noviembre';
12: mes := 'Diciembre';
end;
LABEL18.CAPTION:=DIA +' '+ IntToStr(Day) + ' de ' + mes + ' de ' + IntToStr(Year);
panel1.Visible:=True;
StatusBar1.SimpleText:='Para modificar la hora o el concepto de la tarea
haga doble clic sobre la tarea';
stringgrid2.ColCount:=5;
stringgrid2.RowCount:=50 ;
Stringgrid2.ColWidths[0]:=80;
Stringgrid2.ColWidths[1]:=450;
Stringgrid2.ColWidths[2]:=50;
Stringgrid2.ColWidths[3]:=0;
Stringgrid2.ColWidths[4]:=0;
for I := 1 to StringGrid2.RowCount - 1 do
StringGrid2.Rows[i].Clear;
with Stringgrid2 do
begin
Cells[0, 0] := '' ;
Cells[0,1] := '9:00 a.m.' ;
Cells[0,2] := '9:30 a.m.' ;
Cells[0,3] := '10:00 a.m.' ;
Cells[0,4] := '10:30 a.m.' ;
Cells[0,5] := '11:00 a.m.' ;
Cells[0,6] := '11:30 a.m.' ;
Cells[0,7] := '12:00 p.m.' ;
Cells[0,8] := '12:30 p.m.' ;
Cells[0,9] := '1:00 p.m.' ;
Cells[0,10] := '1:30 p.m.' ;
Cells[0,11] := '2:00 p.m.' ;
Cells[0,12] := '2:30 p.m.' ;
Cells[0,13] := '3:00 p.m.' ;
Cells[0,14] := '3:30 p.m.' ;
Cells[0,15] := '4:00 p.m.' ;
Cells[0,16] := '4:30 p.m.' ;
Cells[0,17] := '5:00 p.m.' ;
Cells[0,18] := '5:30 p.m.' ;
Cells[0,19] := '6:00 p.m.' ;
Cells[0,20] := '6:30 p.m.' ;
Cells[0,21] := '7:00 p.m.' ;
Cells[0,22] := '7:30 p.m.' ;
Cells[0,23] := '8:00 p.m.' ;
Cells[0,24] := '8:30 p.m.' ;
Cells[0,25] := '9:00 p.m.' ;
end;
with query1 do begin
close;
sql.clear;
sql.add('SELECT * from tareas');
SQL.add('where fecha =' + QUOTEDSTR(FormatDateTime('yyyy/mm/dd',xxxx.Date)));
execSQL;
open;
end;
Query1.first; while not (Query1.eof) do
begin
with stringgrid2 do
begin
Present:= Query1.FieldValues['hora'];
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
case hour of
9: x:=1;
10: x:=3;
11: x:=5;
12: x:=7;
1: x:=9;
2: x:=11;
3: x:=13;
4: x:=15;
5: x:=17;
6: x:=19;
7: x:=21;
8: x:=23;
end;
if Query1.fieldvalues['tarea']=null then
Cells[1, x] := ''
else
Cells[1, x] :=(Query1.fieldvalues['tarea']);
if Query1.fieldvalues['folio']=null then
Cells[3, x] := ''
else
Cells[3, x] :=inttostr(Query1.fieldvalues['folio']);
if ((Query1.fieldvalues['status']=null) or (Query1.fieldvalues['status']=0)) then
Cells[4, x] := '0'
else
Cells[4, x] :='1';
inc(x);
end;
Query1.Next;
end;
agregachecks.Click
end;
hasta aqui todo va bien .....
en el agregachecks tengo lo sig.
Código Delphi
[-]
procedure TForm3.agregachecksClick(Sender: TObject);
var
i: Integer;
NewCheckBox: TCheckBox;
Rect: TRect;
begin
clean_previus_buffer.click; for i := 1 to stringgrid2.RowCount do
begin
NewCheckBox := TCheckBox.Create(Application);
NewCheckBox.Width := 0;
NewCheckBox.Visible := false;
NewCheckBox.Caption := '';
if (StringGrid2.Cells[4,i]='1') then
NewCheckBox.Checked :=True
else
NewCheckBox.Checked :=false ;
NewCheckBox.Color := clwhite;
NewCheckBox.Tag := i;
NewCheckBox.OnClick := CheckBox3.OnClick;
NewCheckBox.Parent := Panel1;
StringGrid2.Objects[2,i] := NewCheckBox;
StringGrid2.RowCount := i;
end;
for i := 1 to StringGrid2.RowCount do
begin
NewCheckBox := (StringGrid2.Objects[2,i] as TCheckBox);
if NewCheckBox <> nil then
begin
Rect := StringGrid2.CellRect(2,i); NewCheckBox.Left := StringGrid2.Left + Rect.Left+2;
NewCheckBox.Top := StringGrid2.Top + Rect.Top+2;
NewCheckBox.Width := Rect.Right - Rect.Left;
NewCheckBox.Height := Rect.Bottom - Rect.Top;
NewCheckBox.Visible := True;
end;
end;
end;
hasta aqui llevo todo bien me salen las tareas del dia, me salen marcadas o desmarcadas segun el valor que tengan en la tabla.
si marco primero la descripcion (columna 1 de la stringgrid) y luego le hago clic al checkbox me funciona muy bien ....
el punto es que si no hago un clic previo en la stringgrid y hago un clic en el checkbox directamente, pues no me hace nada por queno reconoce el numero de fila o peor aun me modifica el ultimo que halla seleccionado...
en el evento onclic del checkbox3 tengo lo siguiente
Código Delphi
[-]
procedure TForm3.CheckBox3Click(Sender: TObject);
begin
IF StringGrid2.Cells[4,StringGrid2.Row]='' THEN
ShowMessage('Haga un clic sobre la tarea que quiere modificar');
if (StringGrid2.Cells[4,StringGrid2.Row]='0') then
begin
queryng2x.Close;
queryng2x.SQL.Text:='update tareas set status=1 where folio=' + StringGrid2.Cells[3,StringGrid2.Row];
queryng2x.ExecSQL;
end;
if (StringGrid2.Cells[4,StringGrid2.Row]='1') then
begin
queryng2x.Close;
queryng2x.SQL.Text:='update tareas set status=0 where folio=' + StringGrid2.Cells[3,StringGrid2.Row];
queryng2x.ExecSQL;
end;
end;
ya entendi el concepto del tag, este es el numero de indice cuando se tiene un arreglo de controles, pero el punto es como lo obtengo. o como lo paso al checkbox3.
o si estoy mal con eso, tal vez no sea necesario tenerlo asociado a un checkbox ya creado, bueno compañeros esa es la situacion espero que teniendo el codigo me puedan orientar un poco mas.