![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 6 of 6 total |
![]() |
Tue, Jul 21 2015 2:36 AM | Permanent Link |
Max Evans | Hi guys,
I am trying to customise the background.fill.color of a TPanel by setting the color value from a string. Essentially, after login from my EWB app, the server sends back a color value in ARGB format (eg $FFF00000) and I'm trying to set the panel to this color. StrToInt throws a invalid integer exception.I'm looking for any ideas on how to do this... Cheers Max |
Tue, Jul 21 2015 8:51 AM | Permanent Link |
Michael Dreher | Max Evans wrote:
// I am trying to customise the background.fill.color of a TPanel by setting the color v // alue from a string. // // Essentially, after login from my EWB app, the server sends back a color value in // ARGB format (eg $FFF00000) and I'm trying to set the panel to this color. // // StrToInt throws a invalid integer exception.I'm looking for any ideas on how to do this... I_ve not found a StringToInt function, so I wrote some helper functions... function HexCharToInt(c :char) : integer; begin if ('0'<=c) AND (c<='9') then Result := Ord(c) - Ord('0'); if ('a'<=c) AND (c<='f') then Result := Ord(c) - Ord('a') + 10; if ('A'<=c) AND (c<='F') then Result := Ord(c) - Ord('A') + 10; end; function Hex2ToInt(two_hex_digits : string) : integer; begin Result := HexCharToInt(two_hex_digits[2]) + HexCharToInt(two_hex_digits[1]) * 16; end; // in: something like 'FFF00000 function ARGB_in_hex_to_int(argb : string) : integer; var r, g, b, a : integer; begin b := Hex2ToInt(Copy(argb, 7, 2)); g := Hex2ToInt(Copy(argb, 5, 2)); r := Hex2ToInt(Copy(argb, 3, 2)); a := Hex2ToInt(Copy(argb, 1, 2)); Result := (r SHL 16) OR (g SHL 8) OR (b SHL 0) OR (a SHL 24); end; procedure TfmMain.btSendRequestClick(Sender: TObject); begin panel1.Client.Background.Fill.Color := ARGB_in_hex_to_int('FF00FF00'); // set to green // ... end; Michael Dreher |
Tue, Jul 21 2015 9:06 AM | Permanent Link |
Michael Dreher | // I_ve not found a StringToInt function... I did mean HexToInt. M. Dreher |
Tue, Jul 21 2015 9:47 AM | Permanent Link |
Matthew Jones | According to the internet, the Javascript parseInt function takes a
parameter that "If the string begins with "0x", the radix is 16 (hexadecimal)". That may be worth trying with StrToInt, as there is no source, so I presume it passed it through to parseInt. Or working out how to call parseInto directly. -- Matthew Jones |
Tue, Jul 21 2015 7:51 PM | Permanent Link |
Max Evans | Michael, thanks so much for your effort. Works beautifully.
|
Wed, Jul 22 2015 12:25 AM | Permanent Link |
Trinione | << Michael, thanks so much for your effort. Works beautifully. >>
Hi Max: Can you share the code that works as it may be of assistance to others at some point? Thanks. |
This web page was last updated on Thursday, March 23, 2023 at 02:07 AM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |