procedure TDBCalendarControl.DataChange(Sender: TObject);
begin
if (FDataLink.Field <>
nil)
and not FDataLink.DataSourceFixed
then
begin
if FMaxRecords <> FDataLink.DataSet.RecordCount - 1
then
begin
FMaxRecords := FDataLink.DataSet.RecordCount - 1;
LoadDatesForMonth;
end;
end;
end;
procedure TDBCalendarControl.LoadDatesForMonth;
var
I : Integer;
DT : TDateTime;
Y,
M,
D : Word;
B : TBookmarkStr;
begin
if not IsDateTimeField
then
begin
Exception.CreateFmt('
This Field ''
%s''
is not a DateTimeField.', [FDataLink.FieldName]);
Exit;
end;
DecodeDate(FDate, Y, M, D);
D := 32;
try
while not IsValidDate(Y, M, D)
do Dec(D);
except
end;
B := FDataLink.DataSet.Bookmark;
FDataLink.DataSourceFixed := True;
for I := 1
to D
do
begin
DT := EncodeDate(Y, M, I);
if FDataLink.DataSet.Locate(FDataLink.FieldName,
DT,
[loCaseInsensitive, loPartialKey])
then
FDates[I] := Trunc(FDataLink.Field.AsDateTime);
end;
Invalidate;
FDataLink.DataSourceFixed := False;
FDataLink.DataSet.Bookmark := B;
end;