TAChart: Accept date/time strings in TListChartSource.DataPoints

git-svn-id: trunk@56940 -
This commit is contained in:
wp 2018-01-03 17:36:12 +00:00
parent 3d107d6533
commit 2a5154bef1
2 changed files with 16 additions and 3 deletions

View File

@ -351,6 +351,8 @@ function Split(
// Accept both locale-specific and default decimal separators. // Accept both locale-specific and default decimal separators.
function StrToFloatDefSep(const AStr: String): Double; function StrToFloatDefSep(const AStr: String): Double;
// .. or date/time values
function StrToFloatOrDateTimeDef(const AStr: String): Double;
// Call this to silence 'parameter is unused' hint // Call this to silence 'parameter is unused' hint
procedure Unused(const A1); procedure Unused(const A1);
@ -532,6 +534,16 @@ begin
Result := 0.0; Result := 0.0;
end; end;
function StrToFloatOrDateTimeDef(const AStr: String): Double;
begin
if
not TryStrToFloat(AStr, Result, DefSeparatorSettings) and
not TryStrToFloat(AStr, Result) and
not TryStrToDateTime(AStr, Result)
then
Result := 0.0;
end;
{$PUSH}{$HINTS OFF} {$PUSH}{$HINTS OFF}
procedure Unused(const A1); procedure Unused(const A1);
begin begin

View File

@ -334,17 +334,18 @@ var
var var
i: Integer; i: Integer;
s: String;
begin begin
parts := Split(AString); parts := Split(AString);
try try
if FSource.YCount + 3 < Cardinal(parts.Count) then if FSource.YCount + 3 < Cardinal(parts.Count) then
FSource.YCount := parts.Count - 3; FSource.YCount := parts.Count - 3;
with ADataItem^ do begin with ADataItem^ do begin
X := StrToFloatDefSep(NextPart); X := StrToFloatOrDateTimeDef(NextPart);
if FSource.YCount > 0 then begin if FSource.YCount > 0 then begin
Y := StrToFloatDefSep(NextPart); Y := StrToFloatOrDateTimeDef(NextPart);
for i := 0 to High(YList) do for i := 0 to High(YList) do
YList[i] := StrToFloatDefSep(NextPart); YList[i] := StrToFloatOrDateTimeDef(NextPart);
end; end;
Color := StrToIntDef(NextPart, clTAColor); Color := StrToIntDef(NextPart, clTAColor);
Text := NextPart; Text := NextPart;