procedure TMainForm.btnGlucDataClick(Sender: TObject);
const
FormatFrom: TFormatSettings = (DateSeparator: '-'; ShortDateFormat: 'yyyy-mm-dd');
FormatTo: TFormatSettings = (DateSeparator: '-'; ShortDateFormat: 'dd-mm-yyyy');
DoubleFormat: TFormatSettings = (DecimalSeparator: '.');
Days : array[1..7] of string
= ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var
LoopNodes : IDOMNodeList;
i: Integer;
DateTime: TDateTime;
Val: Extended;
strVal, strValText: string;
begin
XMLDoc.FileName := '.\G1839366.XML';
XMLDoc.Active := True;
try
LoopNodes:= XMLDoc.DOMDocument.getElementsByTagName( 'BG' );
lstvGlucose.Items.BeginUpdate;
try
lstvGlucose.Items.Clear;
for i:= 0 to LoopNodes.length -1 do
with lstvGlucose.Items.add do
begin
if TryStrToDate(LoopNodes[i].attributes.getNamedItem('Dt').nodeValue, DateTime, FormatFrom) then
begin
Caption:= Days[ DayOfWeek(DateTime) ];
SubItems.Add( DateToStr( DateTime, FormatTo ) );
end
else
begin
Caption:= 'can''t convert date';
SubItems.Add( LoopNodes[i].attributes.getNamedItem('Dt').nodeValue );
end;
SubItems.Add( LoopNodes[i].attributes.getNamedItem('Tm').nodeValue );
SubItems.Add( LoopNodes[i].attributes.getNamedItem('Val').nodeValue );
strVal:= StringReplace(LoopNodes[i].attributes.getNamedItem('Val').NodeValue, ',', '.', []);
strValText:= '';
if TryStrToFloat( strVal, Val, DoubleFormat ) then
if Val < 4 then
strValText:= 'HYPO'
else if Val > 10 then
strValText:= 'HYPER';
SubItems.Add( strValText );
end;
finally
lstvGlucose.Items.EndUpdate;
end;
finally
XMLDoc.Active := False;
end;
end;
|