Mirror

How to create logical colour palettes (Views: 100)


Problem/Question/Abstract:

Can someone explain the palPalEntry? I don't understand what the array[0..0] does and how to use it.

Answer:

You can use this for indicating the number of colours your palette is to contain. You should allocate memory for the palette dynamically, this way you can decide how much memory you want to put aside for the palette, i.e.

var
  LogPal: PLogPalette;
  Palette: HPalette;
  PalSize: LongInt;
begin
  { ... }
  PalSize := 2 * SizeOf(Word) + n_Colors * SizeOf(TPaletteEntry));
{2 * SizeOf(Word) to get space for palVersion and palNumEntries,  n_Colors is the number
of colors in the palette}
GetMem(LogPal, PalSize);
LogPal^.palVersion := $0300;
LogPal^.palNumEntries := n_Colors;
LogPal^.palPalEntry[0] := {Some colour};
LogPal^.palPalEntry[1] := {Some other colour};
{ etc. }
FreeMem(LogPal, PalSize);
{ ... }
end;

This has to be compiled with $R- (no range checking), otherwise you will get an error when you try using palPalEntry with an index higher than 0.

<< Back to main page