如何创建DateTime的动态数组?

时间:2012-11-29 19:34:18

标签: .net arrays delphi-prism oxygene

我需要创建一个DateTime的动态数组,但我不知道我需要添加多少日期。我做过ArrayList实验,但没有用。

那么,如何在Delphi Prism中创建DateTime的动态数组?

这是你怎么做的?

mydates: array of DateTime;

更新1

我做了以下操作,编译器说没有带这些参数的重载set_BoldedDates。“

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

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

以上代码仅在我按如下方式设置mydates时才有效:

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

谢谢,

1 个答案:

答案 0 :(得分:3)

这对我来说很好,并正确显示日期。 (注意:解析错误或超出范围的日期没有错误处理!这严格用于显示在Delphi Prism中使用array of DateTimeMonthCalendar.BoldedDates。)

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;

在文本框中输入5的测试会显示以下结果:

Sample display of bolded dates