Board index » delphi » Careful with TBitmap

Careful with TBitmap

Be careful if you have both WinTypes and Graphics in your uses clause, and you
want to declare a variable of the object type TBitmap... Since it is also a
Type in the WinAPI, it conflicts. Thus:

     btmp: TBitmap

     Will NOT work if your uses clause is set as I said. (Delphi thinks it is
the record type, you'll see the problems when you try to create it)

     The workaround is:

     btmp: Graphics.TBitmap

Just a tidbit I ran into that I thought might save someone else some grief...
_
PA will be beautiful, if they ever finish it!

+------------------------------------------------------------+
|* Chad Z. Hower  -  phoe...@pobox.com                       |
|* Consultant - Phoenix Business Enterprises                 |
|         p...@pobox.com   -   http://pobox.com/~pbe          |
|* Principal Analyst Programmer -                            |
|         SCB Computer Technology Inc - czho...@eastman.com  |
|Physically in Church Hill, TN - Logically Not Sure          |
|     **** My Opinions are my own, I don't steal them ****   |
+------------------------------------------------------------+

Quote
>>SQUID - The ultimate database reader, and NO limits. #$737961

**Special Compile: 1.033B (Beta)
 

Re:Careful with TBitmap


Quote
p...@pobox.com wrote:
>Be careful if you have both WinTypes and Graphics in your uses clause, and you
>want to declare a variable of the object type TBitmap... Since it is also a
>Type in the WinAPI, it conflicts. Thus:

>     btmp: TBitmap

>     Will NOT work if your uses clause is set as I said. (Delphi thinks it is
>the record type, you'll see the problems when you try to create it)

>     The workaround is:

>     btmp: Graphics.TBitmap

>Just a tidbit I ran into that I thought might save someone else some grief...

        Actually I believe that if you say

uses Graphics,WinTypes;

then TBitmap=WinTypes.TBitMap, and you would need to say Graphics.TBitmap if
that's what you wanted, while if OTOH you say

uses Winypes,Graphics;

the TBitmap=Graphics.TBitmap and you need to be explicit to get a WinTypes.TBitmap.

        (Which is why WinTypes comes before Graphics in the generic new-project
uses clause.)

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Re:Careful with TBitmap


Quote
>    Actually I believe that if you say

>uses Graphics,WinTypes;

>then TBitmap=WinTypes.TBitMap, and you would need to say Graphics.TBitmap if
>that's what you wanted, while if OTOH you say

     Yes, you are right. But the point is that their are two conflicting
defintions (Probably a mistake, the object version IMHO should have been
given a unique name). For good style, you should ALWAYS fully qualify both
instances in any module that contains both in the uses clause.

     Additionally, I have inherited the TBitmap to a new object, and use
that. Thus guaranteeing they are seperate, and making the code easier to
understand.
_
We have two seasons in PA: Winter and Construction.

+------------------------------------------------------------+
|Chad Z. Hower  -  phoe...@pobox.com                         |
|Phoenix Business Enterprises - p...@pobox.com                |
|            http://pobox.com/~pbe                           |
|Physically in Church Hill, TN - Logically Not Sure          |
+------------------------------------------------------------+

Quote
>>SQUID - The ultimate database reader, and NO limits. #$737961

**Special Compile: 1.033B (Beta)

Re:Careful with TBitmap


Quote
p...@pobox.com wrote:

: >  Actually I believe that if you say
: >
: >uses Graphics,WinTypes;
: >
: >then TBitmap=WinTypes.TBitMap, and you would need to say Graphics.TBitmap if
: >that's what you wanted, while if OTOH you say

:      Yes, you are right. But the point is that their are two conflicting
: defintions (Probably a mistake, the object version IMHO should have been
: given a unique name). For good style, you should ALWAYS fully qualify both
: instances in any module that contains both in the uses clause.

As I've said incessantly, the 'T' prefix is fairly meaningless since it's
so overused. TBitmap - is it an object, a record, or something else?
Can't tell. TDateTime - is it an object, a record, or something else?
Don't know.

A class is more than just a datatype, and should be identified accordingly.

The T prefix on classes should go away, IMHO, replaced by something
more meaningful. VCL classes could have a 'VCL', or just 'V' prefix.
Third party classes could have unique prefixes depending on the
vendor, or the product family.  

--
Jonathan W. Hendry      j...@exnext.com                steel...@ix.netcom.com
Steel Driving Software, Inc.    Delphi And OPENSTEP Software & Consulting
Partner, Hendry & Associates, Delphi & Java Training Services
List maintainer, delphi-announce mailing list

Re:Careful with TBitmap


Quote
>But the point is that their are two conflicting
>defintions (Probably a mistake, the object version IMHO should have been
>given a unique name).

        Certainly calling them both TBitmap was an incredibly awful idea,
just thought I'd point out that which one is the "default" depends on the
order they're listed in "uses" - seems like it could be a useful thing to
know in general...

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Other Threads