Recent

Author Topic: [Solved] Using TColorRec colors for bar series  (Read 1977 times)

artem101

  • Jr. Member
  • **
  • Posts: 84
[Solved] Using TColorRec colors for bar series
« on: July 26, 2022, 09:11:21 am »
How to set SeriesColor using color names from System.UITypes unit? For example:
Code: Pascal  [Select][+][-]
  1. BarSeries.SeriesColor := TColorRec.GreenYellow;

Color looks not as expected:
(https://i.ibb.co/vqvnBYz/2022-07-26-100854.png)

Seems there is another RGB bytes order.
Code: Pascal  [Select][+][-]
  1. WriteLn(IntToHex(clBlue, 8));
  2. WriteLn(IntToHex(TColorRec.Blue, 8));
Quote
00FF0000
000000FF

How to convert this correctly?
« Last Edit: July 27, 2022, 07:48:39 pm by artem101 »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Using TColorRec colors for bar series
« Reply #1 on: July 26, 2022, 10:29:32 am »
Hi!

00FF0000 is the internal format of fpc for Blue - Intel Format

000000FF is the official representation from W3 for Blue - Motorola Format.

If you want to convert the second to the first you have to swap the TColor (32 bit DWord)

Winni

dje

  • Full Member
  • ***
  • Posts: 134
Re: Using TColorRec colors for bar series
« Reply #2 on: July 26, 2022, 11:01:07 am »
Id say the Lazarus System.UITypes (TColorRec) colors are incorrect.

They don't match the Delphi constants.
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.UITypes.TColorRec

So, The documentation is also incorrect:
https://wiki.freepascal.org/Colors#Table_of_standard_colors

EG:
Delphi defines Darkblue = TColor($8B0000);
Lazarus defines DarkBlue = TColor($00008B);
« Last Edit: July 26, 2022, 11:03:46 am by derek.john.evans »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Using TColorRec colors for bar series
« Reply #3 on: July 26, 2022, 11:07:16 am »
Hi!

Besides incorrect documentation and the weird hunt for Delphi compatibility:

The solution for artem101 is:

Code: Pascal  [Select][+][-]
  1. ColorToPaint := swap (TColorRec.Blue);

Winni

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Using TColorRec colors for bar series
« Reply #4 on: July 26, 2022, 11:44:07 am »
So, The documentation is also incorrect:
https://wiki.freepascal.org/Colors#Table_of_standard_colors
Actually, they also don't state they are Delphi compatible.

Only the first 20 are Delphi compatible:
Quote
About 20 predefined color constants are provided, which are Delphi-compatible:

For the other colors it states:
Quote
In FPC 3.2.0+ defines some other constants for w3c colors in System.Uitypes:

So technically the documentation is correct.
It's just not Delphi compatible for the other colors (I'm not sure what the reason is behind this).

dje

  • Full Member
  • ***
  • Posts: 134
Re: Using TColorRec colors for bar series
« Reply #5 on: July 26, 2022, 12:01:26 pm »
The unit was clearly added for "Delphi Compatible" reasons. As far as I can see, the colors are incorrectly defined. Its funny anyone would argue "Delphi Compatible" is not important (ie: weird), when this unit was added to address Delphi compatibility issues. Considering "compatible" is quoted at least 20+ times in the 2.2.0 release notes, I'd say at least one person considers it not weird.

Quote
UITypes unit is deprecated
The UITypes unit is deprecated in favor of System.UITypes, which is available in FPC 3.2.0 and up.
    Reason: System.UITypes is a superset of UITypes and contains some additional constants (Delphi-compatible).
    Remedy: Use System.UITypes unit instead of UITypes unit in your programs.
https://wiki.freepascal.org/Lazarus_2.2.0_release_notes

Quote
Uitypes is in FPC since FPC 3.2.0 as "system.uitypes"  (rtl-objpas), and also includes the "web colors", like delphi does.
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/38937

Quote
Some very general types are in "types" and system.uitypes (the latter in the upcoming FPC 3.2+).  These also exist in Delphi. (types since D7, System.UITypes since DXE2 I think).
https://forum.lazarus.freepascal.org/index.php?topic=48137.0

Quote
Since FPC 3.2.0, Free Pascal defines TColor and TColorRec as well as the 140 standard Color names in the Delphi compatible System.UItypes unit
https://wiki.freepascal.org/Colors
« Last Edit: July 26, 2022, 12:07:36 pm by derek.john.evans »

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Using TColorRec colors for bar series
« Reply #6 on: July 26, 2022, 12:12:21 pm »
Actually, I should have checked trunk and the change log before.

They did swap the colors in the latest version.

Code: Pascal  [Select][+][-]
  1.       DarkBlue           = TColor($8B0000);

Quote
Revision: 742ec5680f8edfdae744382f565a3fda804b0e5c
Author: marcoonthegit <marcov@freepascal.org>
Date: 28-12-2021 18:18:08
Message:
* 24-bit byteswap color constants. Due to Opengl vs GDI conventions confusion?

----
Modified: packages/rtl-objpas/src/inc/system.uitypes.pp


wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Using TColorRec colors for bar series
« Reply #7 on: July 26, 2022, 12:29:27 pm »
Whatever the order of rgb in the widgetset pixels, in TColor it is well-defined. Since all times, clRed has been 255, and this means that red is the lower-order byte in TColor (--> $BBGGRR). When the red and blue in the specific TColorRec values are exchanged, then this clearly is a bug. Please report this to the FPC bugtracker.

rvk

  • Hero Member
  • *****
  • Posts: 6112
Re: Using TColorRec colors for bar series
« Reply #8 on: July 26, 2022, 12:35:25 pm »
Whatever the order of rgb in the widgetset pixels, in TColor it is well-defined. Since all times, clRed has been 255, and this means that red is the lower-order byte in TColor (--> $BBGGRR). When the red and blue in the specific TColorRec values are exchanged, then this clearly is a bug. Please report this to the FPC bugtracker.
As stated in my previous post, this has already been fixed in revision 742ec56 (28-12-2021).

It's just the documentation that's a bit behind (for that a report could be made).

@artem101, when coding in the swapping in the older FPC you need to make sure to undo this when upgrading to a newer FPC (or put the swap between IFDEF for the older version).

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Using TColorRec colors for bar series
« Reply #9 on: July 26, 2022, 12:36:10 pm »
Whatever the order of rgb in the widgetset pixels, in TColor it is well-defined. Since all times, clRed has been 255, and this means that red is the lower-order byte in TColor (--> $BBGGRR). When the red and blue in the specific TColorRec values are exchanged, then this clearly is a bug. Please report this to the FPC bugtracker.

Afaik 3.2.0 only centralized the tcolor type in system.uitypes (so that it was defined and usable by FPC packages, and not just LCL apps). I tried to quickly fix the colors before 3.2.2, but that went wrong due to the endianess.

As it is already fixed in trunk and already merged back to fixes, I don't think a new report is necessary. Unless there are confirmed problems with the situation in fixes.

Wiki is not formal documentation, anybody can fix/edit it, so no report needed.

« Last Edit: July 26, 2022, 01:26:10 pm by marcov »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Using TColorRec colors for bar series
« Reply #10 on: July 26, 2022, 01:27:38 pm »
rvk, sorry, I did not see your post, just saw signs of yet another emerging "delphi-compatibility war" in the other posts.

Marco, what is the advantage of declaring these web colors as consts within a record? What a strange construction for an old man like me... Why not clAliceBlue instead of TColorRec.AliceBlue? Are the Embarcadero devs so fond of typing?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Using TColorRec colors for bar series
« Reply #11 on: July 26, 2022, 03:53:55 pm »
Marco, what is the advantage of declaring these web colors as consts within a record?

I assume you already know the answer ? Delphi compatibility.

Quote
Are the Embarcadero devs so fond of typing?

The only advantage I can image is that you can use a type alias to reference It does allow to reexport the type and all its constants using a type alias, e.g. in a widgetset specific unit.

But it might as well as some java or .net class analogue.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Using TColorRec colors for bar series
« Reply #12 on: July 26, 2022, 07:42:38 pm »
Hi!

If you want to get around all this errors and troubles then use the BGRAbitmap. In the cssColorConst.inc - part of the unit BGRAbitmapTypes - there are all VGA-Colors and all Css-Colors defind. 

Since years.
Without errors.

Winni

artem101

  • Jr. Member
  • **
  • Posts: 84
Re: Using TColorRec colors for bar series
« Reply #13 on: July 26, 2022, 08:25:26 pm »
If you want to get around all this errors and troubles then use the BGRAbitmap. In the cssColorConst.inc - part of the unit BGRAbitmapTypes - there are all VGA-Colors and all Css-Colors defind. 

Nice idea, but I do not want to include additional library only for color constants.

I think it's better for me to add byte order temporary fix before it will be fixed in future release.

artem101

  • Jr. Member
  • **
  • Posts: 84
Re: Using TColorRec colors for bar series
« Reply #14 on: July 26, 2022, 08:48:05 pm »
Actually, I should have checked trunk and the change log before.

They did swap the colors in the latest version.

Code: Pascal  [Select][+][-]
  1.       DarkBlue           = TColor($8B0000);

Quote
Revision: 742ec5680f8edfdae744382f565a3fda804b0e5c
Author: marcoonthegit <marcov@freepascal.org>
Date: 28-12-2021 18:18:08
Message:
* 24-bit byteswap color constants. Due to Opengl vs GDI conventions confusion?

----
Modified: packages/rtl-objpas/src/inc/system.uitypes.pp

But somehow they didn't include this fix in latest 3.2.2 version, which released several months after in May 22.

Commit: https://gitlab.com/freepascal.org/fpc/source/-/commit/742ec5680f8edfdae744382f565a3fda804b0e5c?view=parallel

 

TinyPortal © 2005-2018