Board index » delphi » Does TPoint need to be longint

Does TPoint need to be longint

Hi,

       I've been trying to trim a few bytes off an application and noticed that
TPoint is a longint. For my purposes (I use a lot of TPoint) I just don't need
longint,     smallint   would do fine in fact about +- 2000. I decided to
define my own as it's just a record

TMyPoint = record
       x: smallint;
       y: smallint;
end;

This looked like it was going to do fine, I did a search and 'replace all' and
everything looked fine till I discovered that half way
through I use PtInRect which throws up a compiler error, incompatable types.

I tried doing if PtInRect(rect, TPoint(var_of_TMyPoint))  but this doesn't work
either, invalid typecast.

It seems a shame to throw away a saving for the sake of one function. Does
anyone know of a way of forcing PtInRect to accept TMyPoint as it seems to be
the only thing stopping me.

tia

Gordon.

__________________

http://members.aol.com/gwhit41980/

 

Re:Does TPoint need to be longint


On 05 Dec 1998 19:53:09 GMT, gwhit41...@aol.com (GWhit41980) wrote:

Quote
>It seems a shame to throw away a saving for the sake of one function. Does
>anyone know of a way of forcing PtInRect to accept TMyPoint as it seems to be
>the only thing stopping me.

Don't typecast, write a conversion function.  Delphi allows records as
the result of a function, so you can use

 function  Mine2Theirs(p: TMyPoint):TPoint;
 begin
    result.x := p.x;
    result.y := p.y;
 end;

You'll suffer a performance hit; generally saving space means wasting
time, and vice versa.

Duncan Murdoch

Re:Does TPoint need to be longint


In article <366baef6.12275...@newshost.uwo.ca>, dmurd...@pair.com (Duncan

Quote
Murdoch) writes:
>Don't typecast, write a conversion function.  Delphi allows records as
>the result of a function, so you can use

> function  Mine2Theirs(p: TMyPoint):TPoint;
> begin
>    result.x := p.x;
>    result.y := p.y;
> end;

>You'll suffer a performance hit; generally saving space means wasting
>time, and vice versa.

>Duncan Murdoch

I'm iterating through fairly large numbers of TPoint so I think converting is
going to
cause intolerable delays. It is however handy to know you can do this so I'm
grateful
for the suggestion. I think I might have a go at writing my own 'point in
rectangle'
function. If I can use smallint I reckon I can save about 75k so I think it's
worth
the trouble.

cheers

Gordon

____________________________

http://members.aol.com/gwhit41980/

Other Threads