Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array of array of TDateTime

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I am trying to declare a multidimensional dynamic array of TDateTimes and I'm getting an error:

Incompatible Types : 'TDateTime' and 'Dynamic array'

Can anyone tell me if there is a way to do this?

Thanks!
Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Since TDateTime is really just a double, you could try creating an array of array of double
 
But then could I store TDateTime values in it? Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Like putting your foot into an old shoe. Just do it!
 
Ok, I switched it to a double and I'm still getting the incompatible TDateTime and dynamic array error on the red line below:

Code:
procedure ProcessVouchers();
var
ProcessList : variant;
HoursWorked : array of array of Double;
excelapp, excelsht : Variant;
personcount, i, j, daysworked, tripsmade : integer;
begin
  Save_Cursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  try
    If not JMSData.qryHoursCalc.IsEmpty then
    begin
      personcount := 0;
      While not JMSData.qryHoursCalc.EOF do
      begin
        inc(personcount);
        JMSdata.qryHoursCalc.Next;
      end;
      ProcessList := VarArrayCreate([0, (personcount - 1), 0, 7], varOleStr);
      JMSData.qryHoursCalc.First;
      For i := 0 to (personcount - 1) do
      begin
        JMSData.qryTemp.SQL.Clear;
        JMSData.qryTemp.SQL.Add('SELECT * FROM JMPHOURS WHERE JURNUM = ' + JMSData.qryHoursCalc.FieldByName('JURNUM').AsString);
        JMSData.qryTemp.Active := True;
        While not JMSData.qryTemp.EOF do
        begin
          inc(daysworked);
          JMSdata.qryTemp.Next;
        end;
        tripsmade := daysworked div 2;
        SetLength(HoursWorked, tripsmade, 3);
        JMSData.qryTemp.First;
        for j := 0 to (daysworked - 1) do
        begin
          if j mod 2 = 0 then
          begin
Code:
            Hoursworked(j, 0) := StrToDate(DateFormat(JMSData.qryTemp.FieldByName('SERVDATE').AsString));
Code:
            if RightStr(JMSData.qryTemp.FieldByName('TIMETYPE').AsString, 1) = 'I' then
Code:
            Hoursworked(j, 1) := IntToTime(JMSdata.qryTemp.FieldByName('TIMEIO').AsInteger)
Code:
            else if RightStr(JMSData.qryTemp.FieldByName('TIMETYPE').AsString, 1) = 'O' then
Code:
            Hoursworked(j, 2) := IntToTime(JMSdata.qryTemp.FieldByName('TIMEIO').AsInteger);
Code:
          end
          else
          begin
            if RightStr(JMSData.qryTemp.FieldByName('TIMETYPE').AsString, 1) = 'I' then
Code:
            Hoursworked(j - 1, 1) := IntToTime(JMSdata.qryTemp.FieldByName('TIMEIO').AsInteger)
Code:
            else if RightStr(JMSData.qryTemp.FieldByName('TIMETYPE').AsString, 1) = 'O' then
Code:
            Hoursworked(j - 1, 2) := IntToTime(JMSdata.qryTemp.FieldByName('TIMEIO').AsInteger);
Code:
          end;
        end;
        JMSData.qryHoursCalc.Next;
        daysworked := 0;
      end;
    end;
    ProcessList[i , 0] := JMSData.qryHoursCalc.FieldByName('FIRSTNAME').AsString +
     JMSData.qryHoursCalc.FieldByName('LASTNAME').AsString;
    ProcessList[i , 1] := ProperCase(JMSData.qryHoursCalc.FieldByName('FIRSTNAME').AsString
     + ' ' + JMSData.qryHoursCalc.FieldByName('LASTNAME').AsString);
    ProcessList[i , 2] := dateformat(JMSData.qryHoursCalc.FieldByName('SERVDAT').AsString);
    ProcessList[i , 3] := JMSData.qryHoursCalc.FieldByName('TIMETYPE').AsString;
    ProcessList[i , 4] := JMSData.qryHoursCalc.FieldByName('TIMEIO').AsString;
    ProcessList[i , 5] := JMSData.qryHoursCalc.FieldByName('RTM').AsString;
    excelapp:= CreateOleObject('Excel.Application');
    excelapp.Visible := True;
    excelapp.Workbooks.Open('O:\JMS\Vouchers.xls');
    excelsht :=  excelapp.WorkSheets.Item['Data'];
    excelsht.Activate;
    excelsht.Range[excelsht.Cells.Item[2, 1], excelsht.Cells.Item[(personcount + 1), 5]].Value := ProcessList;
    excelapp.Run('Process_Report');
    Sleep(2000);
    excelapp.Worksheets.Item['Report1'].printout;
    excelapp.displayalerts := False;
    excelapp.quit;
  finally
    Screen.Cursor := Save_Cursor;
  end;
end;

I'm also getting missing operator or semicolon errors on the blue lines as well as on the red line.

Any ideas??? Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Just got back from lunch. Give me some time and I'll get back to you.
 
OK - I got it! I was using parens for the array index instead of brackets!! What a helpful error message I received!!! Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Good catch. You may also need to allocate memory for the array(s) with something like this:
Code:
begin
  SetLength(HoursWorked,3000);
  for i := Low(HoursWorked) to High(HoursWorked) do SetLength(HoursWorked[i],3000);

P.S. Don't you just love switching back and forth between VB and Pascal? [dazed]
 
Don't you just love those little things you search for hours trying to figure out and it's something stupid!!!

As far as switching, aren't we suppose to love it??

Thanks for your help (and yes I have a SetLength) everything seems to be working OK now!

Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top