Board index » delphi » HELP! changing the class of your form

HELP! changing the class of your form

Is it possible to change the class of your form at runtime?

What I want to do is have a database of questions, and the
questions are different types.  Some are multiple choice, some
are free response...  I have the forms set up with inheritance,
but I don't really want to use more than one form, I just
want the one form to change to the different types, depending
on the kind of question that was loaded.  

Any help would be greatly appreciated!

        Brad Larsen

 

Re:HELP! changing the class of your form


I am having trouble with the API Palette functions.  I seem to fill up my
logical palette, and select it, but can't "realize" it into my Canvas.
i.e. I get a return of 0 entries mapped to the system palette.  I have
never attempted this before, so I am going pretty blind here!
Here's the basics of my program:

    {API palette structures}
{ TLogPalette = record
    palVersion: Word;
    palNumEntries: Word;
    palPalEntry: array[0..0] of TPalet{*word*249}try;
  end;

  TPalet{*word*249}try = record
    peRed: Byte;
    peGreen: Byte;
    peBlue: Byte;
    peFlags: Byte;
  end; }

type
  PTLogPalette =  ^TLogPalette;  {pointer to LogPalette structure}

var
  pLogPalette: PTLogPalette;
  hMyPalette: HPalette;
  hOldPalette: HPalette;
  numr: Word;

begin
  GetMem(pLogPalette, 4 + 4*128);
  pLogPalette^.palVersion := $300;
  pLogPalette^.palNumEntries := 128;
  abyte := Byte(nil);
  for i := 0 to 127 do
    begin
    pLogPalette^.palPalEntry[i].peFlags := PC_NOCOLLAPSE;
    pLogPalette^.palPalEntry[i].peRed := i;
    pLogPalette^.palPalEntry[i].peGreen := 0;
    pLogPalette^.palPalEntry[i].peBlue := 0;
    end;

  hMyPalette := CreatePalette(pLogPalette^);

  hOldPalette := SelectPalette(Canvas.Handle, hMyPalette, False);

  numr := RealizePalette(Canvas.Handle); {I GET BACK ZERO, AND
                                          NO CHANGE TO THE CANVAS}
end;

Any ideas appreciated!
Dan Metzger  dmetz...@ngdc.noaa.gov

Re:HELP! changing the class of your form


Dan R. Metzger (dmetz...@ngdc.noaa.gov) wrote:
: I am having trouble with the API Palette functions.

:   numr := RealizePalette(Canvas.Handle); {I GET BACK ZERO, AND
:                                           NO CHANGE TO THE CANVAS}

: Any ideas appreciated!

Exactly which Canvas is that?  If it's not in the foreground, and all
the palette indices are "used", then it won't change any colors.  You
can get the foreground window, I believe, using the API call
GetActiveWindow().  There's also a TScreen method that does the same
thing, but Screen must be Created first (and I'm not sure at which
point exactly that happens).

Hope that helps.

Jay
--
Jay Doane | do...@them.com | Them Productions, San Francisco | (415) 621-1305

Re:HELP! changing the class of your form


Quote
bl2...@pegasus.cc.ucf.edu (Brad Larsen) wrote:

>Is it possible to change the class of your form at runtime?

>What I want to do is have a database of questions, and the
>questions are different types.  Some are multiple choice, some
>are free response...  I have the forms set up with inheritance,
>but I don't really want to use more than one form, I just
>want the one form to change to the different types, depending
>on the kind of question that was loaded.  

>Any help would be greatly appreciated!

>    Brad Larsen

I don't think you can change the class of a form while it is loaded
because the form is an instance of the class! But you could solve
your problem by either

- hiding/showing the relevant controls for each question
- putting the relevant sets of controls on different pages of a
  tabbed form
- creating/destroying the relevant controls as you go at runtime

The last is slower but uses less system resources.

--
Best wishes

John Nurick

e-mail: j.nur...@dial.pipex.com
v-mail: <+44|0> 191 281 1306

Other Threads