TDateTimePicker: Setting Min and Max Date lazarus / 31-LCL ---------------------------------------------------------------------- Jvan · 2021-05-07 23:31 This is my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2021-05-07 23:53 Does frmAstCont (which I assume is a form) exist and does it contain a (TDateTimePicker?) dtpAstFchCont control? ---------------------------------------------------------------------- speter · 2021-05-08 00:07 In addition to lucamar's comments, do "cmbPerContAnho" and "cmbPerContMes" exist (have they been created)!? cheers S. ---------------------------------------------------------------------- Jvan · 2021-05-08 14:05 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 · 2021-05-08 14:29 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. ---------------------------------------------------------------------- Jvan · 2021-05-08 16:21 I created a new project with my code. I had the same problem. ---------------------------------------------------------------------- wp · 2021-05-08 17:00 As lucamar and I told you... You access frmAstCont in the OnCreate event of Form1. Looking at the project file you will see that at this time the frmAstCont is not yet created and thus nil. You can use the OnShow or OnActivate events instead. On the other hand, these events may be fired later during execution of the program again. To prevent unwanted side-effects when this happens, I often implement a method "BeforeRun" of the mainform which is called in the project unit immediately before Application.Run. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TForm1 = class(TForm)  ...  public    procedure BeforeRun;    ...  end; procedure TForm1.BeforeRun;begin  _MinMaxFechaContable; end; ---------- program Project;...begin  ....  Application.Initialize;  Application.CreateForm(TForm1, Form1);  Application.CreateForm(TfrmAstCont, frmAstCont);  Form1.BeforeRun;  Application.Run;end. This way the crash due to nonexisting frmAstConCont is prevented. But as you'll notice there is another problem with your comboboxes - I'll leave this to you to find a solution... ---------------------------------------------------------------------- Jvan · 2021-05-08 19:19 Thanks.