Board index » delphi » Delphi and Setting colour palettes

Delphi and Setting colour palettes

Hi,

I am trying to write an application that utilizes a 256 colour scale to map
data to a particular colour in a range 0 - 255.  The problem I am having is
setting up a colour palette.  I use the Windows API call - CreatePalette
however I am having difficulty setting up the TLogPalette structure -

I have the following:

Colour_Scale: TLogPalette;

Colour_Scale.palNumEntries := 256;
Colour_Scale.palVersion := $300;

The problem is that I get a GPF at the end of the loop filling up the
TPalet{*word*249}try structure (R,G,B) components.  Any suggestions on creating a 256
colour palette ?

By the way the TLogPalette structure has a declaration of

.. array[0..0] of TPalet{*word*249}try what does this mean ?

Pasha Mohammed
http://lidar.ists.ca:8000/pasha/mohammed.htm

 

Re:Delphi and Setting colour palettes


Quote
moham...@lidar.ists.ca (Pasha Mohammed) wrote:
>Hi,
>I am trying to write an application that utilizes a 256 colour scale to map
>data to a particular colour in a range 0 - 255.  The problem I am having is
>setting up a colour palette.  I use the Windows API call - CreatePalette
>however I am having difficulty setting up the TLogPalette structure -
>I have the following:
>Colour_Scale: TLogPalette;
>Colour_Scale.palNumEntries := 256;
>Colour_Scale.palVersion := $300;

>The problem is that I get a GPF at the end of the loop filling up the
>TPalet{*word*249}try structure (R,G,B) components.  Any suggestions on creating a 256
>colour palette ?
>By the way the TLogPalette structure has a declaration of
>.. array[0..0] of TPalet{*word*249}try what does this mean ?

You need to allocate the memory dynamically.  The array[0..0]
allocates a single slot, and you need 256 slots.  The reason
TLogPalette is not declared array[0..255] is because there might not
be any entries at all, or there might be more than 256.  That's why
you have to allocate the memory dynamically.  There is no way to tell
the compiler how big your palette really is.

Color_Scale: ^TLogPalette;

GetMem(Color_Scale,  SizeOf(TLogPalette)+255 *Sizeof(TPalet{*word*249}try));

--
Ray Lischner       (li...@tempest-sw.com)
Tempest Software

Other Threads