调度系统的Delphi Week Array存储问题

时间:2021-11-11 14:38:32

I have a form with calenders on it. When the calenders are clicked, they set the variable CurDateSel to the date selected on the calendar.

我有一个带压光机的表格。单击日历时,会将变量CurDateSel设置为日历上选定的日期。

I have a constant array (Week) which has the values of Monday [Index 0] through to Sunday [Index 6] stored.

我有一个常量数组(周),其中存储了星期一[索引0]到星期日[索引6]的值。

I also have a StringGrid which used to have the days of the week spanning across the top of the grid, from Sunday to Monday, however, I have now changed that to show the first column of the grid to be the CurDateSel day (The Now day when the form starts) and the following grid columns to store the days following the day selected.

我还有一个StringGrid,它曾经让星期几跨越网格的顶部,从星期日到星期一,但是,我现在已经改变它以显示网格的第一列是CurDateSel日(The Now表格开始的那一天)和以下网格列,用于存储选定日期之后的日期。

For example, If Saturday were the day selected:

例如,如果星期六是选定的日期:

Saturday|Sunday|Monday|Tuesday|Wednesday|Thursday|Friday  

I then have a procedure which runs through a stored list of Bookings and adds the bookings with the corresponding day and date to the grid. For example, if a booking was on Sat 23rd at 2pm, the procedure would go to 2pm on the y-axis and go to the 5th column on the axis, as this corresponds to Saturday, in my array WEEK.

然后我有一个程序,它运行一个存储的预订列表,并将相应的日期和日期添加到网格中。例如,如果预订是在23日星期六下午2点,则程序将在y轴上下午2点到达轴上的第5列,因为这对应于星期六,在我的阵列周中。

However, as my columns now change according to the current day, the stored booking values do not go to the corresponding days, but go to the columns which would normally store the days if the columns started from Monday and ended on Sunday.

但是,由于我的列现在根据当天更改,因此存储的预订值不会转到相应的日期,而是转到通常存储日期的列,如果列从星期一开始并在星期日结束。

I decided to create a new array which would store the values of the week where the start of the week would be the current day and the end of the week would be the current day + 6 days. I called this array SelDayArray.

我决定创建一个新数组,该数组将存储本周开始的当周日值,而本周结束时为当天+ 6天。我把这个数组称为SelDayArray。

For example, if it were Saturday, this array would start from Index[0] = Saturday and end with Index[6] = Friday.

例如,如果是星期六,则此数组将从Index [0] = Saturday开始,以Index [6] = Friday结束。

I have attempted to write the code to fill this second array, however I seem to have trouble filling it correctly.

我试图编写代码来填充第二个数组,但是我似乎无法正确填充它。

procedure ReturnUpdatedDay;  
 var  
  i, x, p, CurDayNo: Integer;  
begin  
  i := 0;  
  CurDayNo := ReturnDayCell(FormatDateTime('dddd', CurDateSel));  
  repeat  
    SelDayArray[i] := Week[CurDayNo+i];  
    Inc(i);  
  until (CurDayNo + i) = 7;  
  Dec(i);  
  p := i;  
  for x := 0 to (CurDayNo-p) do  
    begin  
      Inc(i);  
      SelDayArray[i] := Week[x];  
    end;
end;

My ReturnDayCell Function returns the DayNo according to a fixed constant array of the array WEEK. Thus, If Saturday were to be selected as the Current Day, the procedure would return 5 and the value of CurDayNo would = 5

我的ReturnDayCell函数根据数组WEEK的固定常量数组返回DayNo。因此,如果将星期六选为当日,则程序将返回5并且CurDayNo的值将= 5

Therefore, my ReturnUpdatedDay procedure should set the values of my SelDayArray to TheCurrentDay [Index 0] to TheCurrentDay+6 [Index 6]

因此,我的ReturnUpdatedDay程序应该将我的SelDayArray的值设置为TheCurrentDay [Index 0]到TheCurrentDay + 6 [Index 6]

This works for the day 'Saturday'. When I print the list into a memo, I recieve the values: Saturday, Sunday, Monday... Friday.

这适用于'星期六'这一天。当我将列表打印成备忘录时,我收到了价值观:星期六,星期日,星期一......星期五。

However, when I try days before saturday, I either receive an access violation error or the last two days of the list are not stored/printed. When I select sunday, I receive an access violation error.

但是,当我在星期六之前几天尝试时,我会收到访问冲突错误,或者列表的最后两天没有存储/打印。当我选择星期日时,我收到访问冲突错误。

Please could someone give me a hand and help me see what I'm doing wrong. Apologies for any typos or confusing pieces of information. Thanks.

请有人帮我看看我做错了什么。为任何拼写错误或令人困惑的信息道歉。谢谢。

1 个解决方案

#1


2  

The mod operator allows you to access the week vector in a circular way, falling back to 0 after the 6th element.

mod运算符允许您以循环方式访问周向量,在第6个元素之后回退到0。

Change your code to this:

将您的代码更改为:

procedure ReturnUpdatedDay;  
 var  
  I, CurDayNo: Integer;  
begin  
  CurDayNo := ReturnDayCell(FormatDateTime('dddd', CurDateSel));  
  for I := 0 to 6 do
    SelDayArray[I] := Week[(CurDayNo + I) mod 7];  
end;

#1


2  

The mod operator allows you to access the week vector in a circular way, falling back to 0 after the 6th element.

mod运算符允许您以循环方式访问周向量,在第6个元素之后回退到0。

Change your code to this:

将您的代码更改为:

procedure ReturnUpdatedDay;  
 var  
  I, CurDayNo: Integer;  
begin  
  CurDayNo := ReturnDayCell(FormatDateTime('dddd', CurDateSel));  
  for I := 0 to 6 do
    SelDayArray[I] := Week[(CurDayNo + I) mod 7];  
end;