Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-07

Commment-2 about TAChart diff

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexey
+ else if (pos('#', AText) = 1) and (Length(AText) = 7) then begin
+ Delete(AText, 1, 1);
+ Result.Red := StrToInt('$' + copy(AText, 1, 2)) shl 8;
+ Result.Green := StrToInt('$' + copy(AText, 3, 2)) shl 8;
+ Result.Blue := StrToInt('$' + copy(AText, 5, 2)) shl 8;
+ end else
+

you convert #rrggbb, but don't convert #rgb (eg #123 means #112233). example from ATSynEdit -

   //allow only #rgb, #rrggbb
   Len:= Length(s);
   if (Len3) and (Len6) then exit;
   for i:= 1 to Len do
     if not IsCharHex(s[i]) then exit;
   if Len=6 then
   begin
     N1:= StrToInt('$'+Copy(s, 1, 2));
     N2:= StrToInt('$'+Copy(s, 3, 2));
     N3:= StrToInt('$'+Copy(s, 5, 2));
   end
   else
   begin
     N1:= StrToInt('$'+s[1]+s[1]);
     N2:= StrToInt('$'+s[2]+s[2]);
     N3:= StrToInt('$'+s[3]+s[3]);
   end;
   Result:= RGBToColor(N1, N2, N3);
end;

my code also has checking for Hex, and yours dont have check for hex. so '#aazz33' will crash.

Regards, Alexey -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170704/f4be0356/attachment.html>

Reply by email

Alexey
+ else if (pos('#', AText) = 1) and (Length(AText) = 7) then begin
+ Delete(AText, 1, 1);
+ Result.Red := StrToInt('$' + copy(AText, 1, 2)) shl 8;
+ Result.Green := StrToInt('$' + copy(AText, 3, 2)) shl 8;
+ Result.Blue := StrToInt('$' + copy(AText, 5, 2)) shl 8;
+ end else
+

you convert #rrggbb, but don't convert #rgb (eg #123 means #112233). example from ATSynEdit -

   //allow only #rgb, #rrggbb
   Len:= Length(s);
   if (Len3) and (Len6) then exit;
   for i:= 1 to Len do
     if not IsCharHex(s[i]) then exit;
   if Len=6 then
   begin
     N1:= StrToInt('$'+Copy(s, 1, 2));
     N2:= StrToInt('$'+Copy(s, 3, 2));
     N3:= StrToInt('$'+Copy(s, 5, 2));
   end
   else
   begin
     N1:= StrToInt('$'+s[1]+s[1]);
     N2:= StrToInt('$'+s[2]+s[2]);
     N3:= StrToInt('$'+s[3]+s[3]);
   end;
   Result:= RGBToColor(N1, N2, N3);
end;

my code also has checking for Hex, and yours dont have check for hex. so '#aazz33' will crash.

Regards, Alexey -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170704/3806fbe7/attachment.html>

Reply by email