Question

I need to create a dynamic array of DateTime, but I don't know before hand how many dates I will have to add. I did experiment with ArrayList, but it doesn't help.

So, how do you create dynamic array of DateTime in Delphi Prism?

Is this how you do it?

mydates: array of DateTime;

UPDATE 1

I did the following and compiler says that there is no overloaded set_BoldedDates with these parameters."

  mydates:ArrayList;
  mydates := new ArrayList;
  mydates.Add(new DateTime(2012,11,23));

  DataCalendar.BoldedDates := mydates; //also I did mydates.ToArray caused error.

The above code only works if I set the mydates as follows:

const
mydates : Array[0..1] of DateTime = [new DateTime(2012,11,23), new Datetime(2012,11,13)];

Thanks,

Était-ce utile?

La solution

This works fine for me, and displays the dates properly. (Note: there is no error handling for parsing errors or out of range dates! This is strictly designed to show the use of the array of DateTime with MonthCalendar.BoldedDates in Delphi Prism.)

method MainForm.button2_Click(sender: System.Object; e: System.EventArgs);
var
  Dt: array of System.DateTime;
  TheSize: Int32;
begin
  TheSize := Int32.Parse(textBox1.Text);

  Dt := new System.DateTime[TheSize];
  for i: Int32 := 0 to TheSize - 1 do
    Dt[i] := new DateTime(2012, 11, i + 4);

  monthCalendar1.BoldedDates := Dt;  
end;

A test entering 5 in the textbox shows this result:

Sample display of bolded dates

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top