Board index » delphi » Wish: assign type pointers like procedure pointers.

Wish: assign type pointers like procedure pointers.

Hi,

Like in graphics you might have this problem of graphics cards using
different pixel color components layout :)

like blue first, then green then red then alpha..
or maybe green first then blue then red etc..

type
 Tpixel1 = packed record // type2
 case integer of
  0 : ( b,g,r,a : Tuint8 );
  1 : ( value : Tuint32 );
 end;

 Tpixel2 = packed record // type2
 case integer of
  0 : ( g,r,b,a : Tuint8 ); // different layout in memory
  1 : ( value : Tuint32 );
 end;

It would be cool if the progam can determine the right layout... and then
switch to the write type...

Now that's impossible ? The programmer could do typcasting and if statements
and case statements... but it would be throoughout the code...

Yet it would be more efficient to switch to the right type at startup and
keeping using that throughout the program.

So sometimes

P : Tpixel1; will be used and sometimes
P : Tpixel2; will be used.

But the programmer can still use
P.a  like nothing changed...

without needing case statements etc..

 

Re:Wish: assign type pointers like procedure pointers.


Quote
Skybuck Flying wrote:

> Hi,

> Like in graphics you might have this problem of graphics cards using
> different pixel color components layout :)

> like blue first, then green then red then alpha..
> or maybe green first then blue then red etc..

> type
>  Tpixel1 = packed record // type2
>  case integer of
>   0 : ( b,g,r,a : Tuint8 );
>   1 : ( value : Tuint32 );
>  end;

>  Tpixel2 = packed record // type2
>  case integer of
>   0 : ( g,r,b,a : Tuint8 ); // different layout in memory
>   1 : ( value : Tuint32 );
>  end;

> It would be cool if the progam can determine the right layout... and then
> switch to the write type...

> Now that's impossible ? The programmer could do typcasting and if statements
> and case statements... but it would be throoughout the code...

> Yet it would be more efficient to switch to the right type at startup and
> keeping using that throughout the program.

> So sometimes

> P : Tpixel1; will be used and sometimes
> P : Tpixel2; will be used.

> But the programmer can still use
> P.a  like nothing changed...

> without needing case statements etc..

You can do what you want using different classes for each type (both
descending from the same parent)

--
=======================================================================
= David    - Visit www.thehungersite.com
= Mitchell - Feed someone for nothing
=======================================================================

Re:Wish: assign type pointers like procedure pointers.


and have a 64.000 pixel array of classess ?

Sounds like overkill.

Descendants for records would be nice.

Quote
"David Mitchell" <da...@edenroad.demon.co.uk> wrote in message

news:3E69D8BE.B1BBA6AF@edenroad.demon.co.uk...
Quote
> Skybuck Flying wrote:

> > Hi,

> > Like in graphics you might have this problem of graphics cards using
> > different pixel color components layout :)

> > like blue first, then green then red then alpha..
> > or maybe green first then blue then red etc..

> > type
> >  Tpixel1 = packed record // type2
> >  case integer of
> >   0 : ( b,g,r,a : Tuint8 );
> >   1 : ( value : Tuint32 );
> >  end;

> >  Tpixel2 = packed record // type2
> >  case integer of
> >   0 : ( g,r,b,a : Tuint8 ); // different layout in memory
> >   1 : ( value : Tuint32 );
> >  end;

> > It would be cool if the progam can determine the right layout... and
then
> > switch to the write type...

> > Now that's impossible ? The programmer could do typcasting and if
statements
> > and case statements... but it would be throoughout the code...

> > Yet it would be more efficient to switch to the right type at startup
and
> > keeping using that throughout the program.

> > So sometimes

> > P : Tpixel1; will be used and sometimes
> > P : Tpixel2; will be used.

> > But the programmer can still use
> > P.a  like nothing changed...

> > without needing case statements etc..

> You can do what you want using different classes for each type (both
> descending from the same parent)

> --
> =======================================================================
> = David    - Visit www.thehungersite.com
> = Mitchell - Feed someone for nothing
> =======================================================================

Re:Wish: assign type pointers like procedure pointers.


Hmm still interesting idea.

Maybe it can be used somehow in the future if I ever face such a situation
:)

The pixel class would just be used to pass color info to classes and
properties that can work with it.

Quote
"David Mitchell" <da...@edenroad.demon.co.uk> wrote in message

news:3E69D8BE.B1BBA6AF@edenroad.demon.co.uk...
Quote
> Skybuck Flying wrote:

> > Hi,

> > Like in graphics you might have this problem of graphics cards using
> > different pixel color components layout :)

> > like blue first, then green then red then alpha..
> > or maybe green first then blue then red etc..

> > type
> >  Tpixel1 = packed record // type2
> >  case integer of
> >   0 : ( b,g,r,a : Tuint8 );
> >   1 : ( value : Tuint32 );
> >  end;

> >  Tpixel2 = packed record // type2
> >  case integer of
> >   0 : ( g,r,b,a : Tuint8 ); // different layout in memory
> >   1 : ( value : Tuint32 );
> >  end;

> > It would be cool if the progam can determine the right layout... and
then
> > switch to the write type...

> > Now that's impossible ? The programmer could do typcasting and if
statements
> > and case statements... but it would be throoughout the code...

> > Yet it would be more efficient to switch to the right type at startup
and
> > keeping using that throughout the program.

> > So sometimes

> > P : Tpixel1; will be used and sometimes
> > P : Tpixel2; will be used.

> > But the programmer can still use
> > P.a  like nothing changed...

> > without needing case statements etc..

> You can do what you want using different classes for each type (both
> descending from the same parent)

> --
> =======================================================================
> = David    - Visit www.thehungersite.com
> = Mitchell - Feed someone for nothing
> =======================================================================

Other Threads