Author Topic: Longint conversion - Solved -  (Read 1005 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Longint conversion - Solved -
« on: July 24, 2009, 05:34:14 am »
Is there any way to convert a longint to/from an integer value? Or convert it to an RGB? I need this for a textbox function im making.

Thankyou
« Last Edit: July 25, 2009, 03:07:03 pm by Hacktank »


Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Longint conversion
« Reply #1 on: July 24, 2009, 05:49:03 am »
RGB(R, G, B: byte): longint;

Code: [Select]
var x: longint;

x := RGB(255, 200, 100); // $FFC864

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Longint conversion
« Reply #2 on: July 24, 2009, 06:56:08 pm »
I need to convert a longint to a RGB not the other way around.


Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Longint conversion
« Reply #3 on: July 24, 2009, 09:37:36 pm »
I need to convert a longint to a RGB not the other way around.
A longint is a RGB. If you want to get the individual components of it then just turn it into hex and take the first 2 characters for R, next 2 for B, etc.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Longint conversion
« Reply #4 on: July 24, 2009, 10:19:50 pm »
Thanks man, but how would I put a longint into that? Is it concidered a string for var use purposes?


Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Longint conversion
« Reply #5 on: July 25, 2009, 11:10:48 am »
Longint can also has alpha information, but it is sometimes ignored.

Code: [Select]
function ARGB(const Alpha, Red, Green, Blue: longint): longint;
begin
  Result := (Alpha shl 24) or (Red shl 16) or (Green shl 8) or Blue;
end;

function GetAlpha(const Color: longint): longint;
begin
  Result := (Color shr 24) and $FF;
end;

function GetRed(const Color: longint): longint;
begin
  Result := (Color shr 16) and $FF;
end;

function GetGreen(const Color: longint): longint;
begin
  Result := (Color shr 8) and $FF;
end;

function GetBlue(const Color: longint): longint;
begin
  Result := Color and $FF;
end;

procedure ActivateServer();
var
  Color, i: longint;
begin
  Color := $FFEFDFCF;
  WriteLn(InttoStr(GetBlue(Color))); // CF, 207
  WriteLn(InttoStr(GetGreen(Color))); // DF, 223
  WriteLn(InttoStr(GetRed(Color))); // EF, 239
  WriteLn(InttoStr(GetAlpha(Color))); // FF, 255
end;

Some reason when I change the return types to byte, it returns 0. I don't got time to figure out how to fix that atm.

EDIT: Well, some of it I understand... <byte> shr <int> returns byte, but not all of it makes sense to me in the Get<Type> functions
« Last Edit: July 25, 2009, 11:47:16 am by DorkeyDear »

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Longint conversion
« Reply #6 on: July 25, 2009, 03:06:50 pm »
Thats awsome Curt!  :o Thanks, that is exactly what i need.