My own palette doesn't work!

I need some controls on my form to appear in a self-defined color. I create
and select a logical palette just the way WinAPI prescribes it. I use
C++Builder 3.0 Professional.

But when I try to assign a palette color to a control, it remains black.
What goes wrong?

This is how my code works (the control that receives the custom color is
called Shape1 on my MainForm) :

///// First a logical palette is constructed with my own, self-defined gray
shades in it:

  HDC hDC;                      // handle to device-context
  HPALETTE hPal = NULL; // handle to my own palette

  LPLOGPALETTE lpPal;   // pointer to a logical palette
  WORD wNumColors;      // number of colors in color table
  wNumColors =  256;
  // allocate memory block for logical palette
  lpPal =
(LPLOGPALETTE)malloc(sizeof(LOGPALETTE)+sizeof(PALET{*word*249}TRY)*wNumColors-1);
  if (!lpPal) // if not enough memory
  {
    ShowMessage("Not enough memory!");
    return NULL;
  }
  // set version and number of palette entries
  lpPal->palVersion = 0x300;
  lpPal->palNumEntries = (WORD)wNumColors;
   for (int i = 0; i < (int)wNumColors; i++)
  {
      lpPal->palPalEntry[i].peRed = i;
      lpPal->palPalEntry[i].peGreen = i;
      lpPal->palPalEntry[i].peBlue = i;
  }
  hPal = CreatePalette (lpPal); // create the palette and get handle to it
  free (lpPal);

///// Then the palette is selected and realized:

  SelectPalette(hDC, hPal, FALSE);
  RealizePalette(hDC);
  UpdateColors(hDC);

///// Finally, I want to assign, let's say, color # 75 to my Shape1:

  Shape1->Brush->Color = PaletteIndex(75);

But my Shape1 remains black. By the way, assigning a default system color
to Shape1 works
(like: Shape1->Brush->Color  = PaletteIndex(3);)

So where are my shades of gray?

Thanks in advance,

--
Johan Hendriks
<joh...@worldonline.nl>