 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Peter Morris [Droopy eyes Guest
|
Posted: Mon Jun 27, 2005 3:58 pm Post subject: TControl.Perform, should be LongWord not LongInt? |
|
|
My DIB controls hijack the standard drawing process. I noticed recently
that Range Checking was disabled by default for my projects, so I turned it
on.
Suddenly I was getting Range Check Error in the following code
ChildControl.Perform(WM_PAINT, DC, 0);
Upon further investigation the cause was this:
The WM_PAINT of my parent control does this (As does the VCL)
if Message.DC = 0 then
DC := BeginPaint(Handle, PaintStructure)
else
DC := Message.DC;
BeginPaint returns a HDC, which is a LongWord (unsigned 32bit), but Perform
uses LongInt (Signed 32 bit). BeginPaint was returning values > MaxInt, and
this was the cause of the problem.
It would seem that the VCL's declaration of Perform is incorrect, and also
the definition of TMessage. I suspect that this may be why range checking
is disabled in Controls.pas!
Now, the problem is, I think it is too late to change. I'd expect that by
now lots of people already have code which sends a message with a -1
parameter. The solution is to hard-cast the value "Integer(DC)" as a
parameter, but I was just surprised to see that a core part of the windows
messaging was defined incorrectly.
--
Pete
====
ECO Modeler, Audio compression components, DIB graphics controls,
FastStrings
http://www.droopyeyes.com
Read or write articles on just about anything
http://www.HowToDoThings.com
My blog
http://blogs.slcdug.org/petermorris/
|
|
| Back to top |
|
 |
Chris Rolliston Guest
|
Posted: Mon Jun 27, 2005 5:18 pm Post subject: Re: TControl.Perform, should be LongWord not LongInt? |
|
|
| Quote: | BeginPaint returns a HDC, which is a LongWord (unsigned 32bit), but
Perform
uses LongInt (Signed 32 bit).
|
Strictly speaking, it should be defined as a WPARAM, I suppose - but WPARAM
is defined as a LongInt in Windows.pas. Yet also strictly speaking, one
should always be typecasting to WPARAM anyway, no? Because WPARAM (as
indeed LPARAM) is just a placeholder for *any* value up to 4 bytes, be it an
HDC, BOOL, LONG, or whatever.
|
|
| Back to top |
|
 |
Peter Morris [Droopy eyes Guest
|
Posted: Mon Jun 27, 2005 5:30 pm Post subject: Re: TControl.Perform, should be LongWord not LongInt? |
|
|
That would make no difference as WPARAM is also defined as LongInt, and
therefore incapable of holding MAXINT + 1
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Tue Jun 28, 2005 10:39 am Post subject: Re: TControl.Perform, should be LongWord not LongInt? |
|
|
| Quote: | That would make no difference as WPARAM is also defined as LongInt, and
therefore incapable of holding MAXINT + 1
ofcourse it can .. it's just wrapped arround |
just like DWORD(-1) :)
|
|
| Back to top |
|
 |
Aleksander Oven Guest
|
Posted: Wed Jun 29, 2005 5:04 pm Post subject: Re: TControl.Perform, should be LongWord not LongInt? |
|
|
| Quote: | ofcourse it can .. it's just wrapped arround
just like DWORD(-1)
|
Exactly. The way I see it, signed types can hold all the values of
their unsigned counterparts just fine. It's just a matter of
interpreting it differently, depending on typecast - i.e. 1 bit
used as a sign instead of contributing to the actual value.
Messages are indeed a good example of this. As established before,
wParam and lParam are declared as LongInts. But there are numerous
Win32 messages which use them for passing various types of Win32
handles around.
And handles are usually unsigned DWORDS. :)
Regards,
Aleksander Oven
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|