Forum > LCL

TDateTimePicker: Setting Min and Max Date

(1/2) > >>

Jvan:
This is my code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmMain._MinMaxFechaContable();var  anho, mes: Integer;  myDtp: TDateTimePicker;begin  anho := 2000 + cmbPerContAnho.ItemIndex;  mes := cmbPerContMes.ItemIndex;  myDtp := frmAstCont.dtpAstFchCont;  if (mes = 0) then begin    //El 1er día del mes seleccionado:    myDtp.MinDate := EncodeDate(anho, 1, 1);    //El 31 de diciembre del año seleccionado:    myDtp.MaxDate := EncodeDate(anho, 12, 31);  end else begin    //El 1er día del mes seleccionado:    myDtp.MinDate := EncodeDate(anho, mes, 1);    //El mes siguiente menos 1 día:    myDtp.MaxDate := IncMonth(myDtp.MinDate, 1) - 1.0;  end; end;  
But I had this error showed in "error1.png".

lucamar:
Does frmAstCont (which I assume is a form) exist and does it contain a (TDateTimePicker?) dtpAstFchCont control?

speter:
In addition to lucamar's comments, do "cmbPerContAnho" and "cmbPerContMes" exist (have they been created)!?

cheers
S.

Jvan:
Yes, they exist. I can see them, so they exist.

"cmbPerContAnho" and "cmbPerContMes" are on the main form. And "dtpAstFchCont" in on a ShowModal form.

wp:
Maybe the form frmAstCont does not yet exist when your code is called? Is it in the list of auto-created forms (in the project options)? Or do you create it at run-time? Maybe you forgot to create it? It's hard to tell without seeing all of your code...

In general: Put a breakpoint into the procedure which raises the exception. When the program stops open "View" > "Debug windows" > "call stack" -- this shows you from which routine the breakpoint procedure is called, and the routine from which this other routine is called etc. Study these lines and check whether the form already exists when they are called.

Navigation

[0] Message Index

[#] Next page

Go to full version