Delphi 3 . Typecasts

I need to manipulate bits within a single. Under D1 I did it like this...
Delphi won't allow bitwise operations on reals (why not!!) so the single is treated as a longint to do the manipulations, then the resulting bit pattern is treated as a single.
    SType = single;
    LType = longint;
    sing1 : single;
    long1 : longint;

long1 := LType(sing1);  {typecast the single as a longint}

{do the SHR, AND, OR manipulations here}

sing1 := SType(long1);  {longint back to a single}

Under D3 I get a compiler error "invalid typecast".
Can anyone tell me why, and how do I fix it.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Instead of typecasting, use the ROUND() function to convert the single to an integer. Also  you don't need to typecast to go the other way.


        sing1 : single;
        long1 : longint;

    long1 := Round(sing1);

    {do the SHR, AND, OR manipulations here}

    sing1 := long1;

rickpetCommented: can't do it directly but you can do it indirectly...pass the address back and forth and manipulate the values of the addresses...

  pMyLongInt = ^Integer;
  pMySingle = ^Single;
  mySingle: single;
  myLongInt: LongInt;
  ptrMyLongInt : pMyLongInt;
  ptrMySingle: pMySingle;
  myPointer: Pointer;

  mySingle := 2.01;
  myPointer := @mySingle;
  ptrmyLongInt := myPointer;
  myLongInt := ptrmyLongInt^;
  myLongInt := myLongInt SHL 1;
  myPointer := @myLongInt;
  ptrMySingle := myPointer;
  mySingle := ptrMySingle^;
  Label1.Caption := FloatToStr(mySingle);

In Delphi 1 you need to change my Type of pMyLongInt to
pMyLongInt = ^LongInt (In 32bit world LongInt = Integer)

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

frogAuthor Commented:
Socrates, thanks for your reply but the round() will convert the real to a longint value and data format, it therefore will not preserve the bit pattern of the single which I want to manipulate.

rickpet, thanks for the pointers reminder. I'm sure it will work, I'll do it when I get time.

frogAuthor Commented:
rickpet I'll accept your answer but I don't think there is any way for me to give you the points until you send it as an answer instead of a comment. Is that right?

rickpetCommented:'s your answer...Thanks...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.