Path: utzoo!news-server.csri.toronto.edu!rutgers!usenet!ogicse!emory!swrinde!zaphod.mps.ohio-state.edu!think.com!hsdndev!cmcl2!adm!news From: CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) Newsgroups: comp.lang.pascal Subject: Re: TP type cast/conversion woes Message-ID: <26261@adm.brl.mil> Date: 13 Mar 91 20:36:53 GMT Sender: news@adm.brl.mil Lines: 97 In article , oecheruo@silver.ucs.indiana.edu (Chima Echeruo) wrote: >I am working on a small windowing system for use in some educational >applications. To handle the mouse I am using a freeware mouse TPU. >My problem is that all the mouse routines take words while most of >my own routine uses integers. For simple things like comparing an >integer variable (say a window co-ord) with a word (say the mouse >x-co-ord) the TP compiler produces incorrect code. Can you demonstrate this "incorrect code", please? I've just examined the code for a sample program (shown below), and it appears to me to be correct in all cases (using TPC.EXE 5.5 and 6.0). Why do your routines use integers? >I have looked throughout the manuals and online help and I cannot >find a convertion function or even a built in type conversion. Why >can't I compare a word and an integer to see which is greater or >smaller. Pending your demonstration, I'm inclined to say, "But you can." >If they have to be converted to some common type, why won't TP do >the conversion at compile time - like any decent computer language. The examples I examined converted (at compile time) both words and integers to double words (long integers) before comparing. >Then, If I have to convert a word value to an integer how do I do >that? there is an Int function but it works only on real numbers. Type cast it--but beware of wrap around of words > MaxInt. Or just assign it (same caveat). some_int := some_word; some_int := integer(some_word); >PS. On a different problem. > >As I said earlier I am working on a graphics windowing unit. Well I >have almost NIL experience in graphics programming and would like Hmmm...reading/writing to NIL is not always a good idea... (bad joke, sorry... ;) ) >some tips about how windows are implemented. I am most concerned >about the sort of data structures that one would use to allow >random access to any window. Right now, I use a simple fixed array >but I cannot tell the order in which the windows were created since >they new windows can be added anywhere in the array. Hopefully your "simple fixed array" is an array of pointers, not of the window structures themselves. That being the case, the cost of swapping items in the array is trivial, and you can keep the array ordered as you please--possibly with the topmost window having the highest current index value. Windows are often implemented using stacks which are implemented with arrays or linked lists. >secondly, how can one implement overlapping windows given the fact >that the BGI graphics only understands one current window. I have >avoided virtual windows that allow updating even when they are >partially hidden. I'm not very knowledgable about BGI, and haven't tried a graphics window implementation myself. Can't you just use SetViewPort to change from one window to another? (Obviously you'd be responsible for saving and restoring overwritten window contents. I'd think GetImage and PutImage would do well for that.) What version of TPas are you using? Do you have the documentation for it? Sample program for checking integer<->word comparisons: {$R-,S-,V-,I-} var w1, w2 : word; i1, i2 : integer; begin if w1 < w2 then if i1 < i2 then if w1 < i1 then if i1 < w1 then; end. +--------------------------------------------------------------------+ | Karl Brendel Centers for Disease Control | | Internet: CDCKAB@EMUVM1.BITNET Epidemiology Program Office | | Bitnet: CDCKAB@EMUVM1 Atlanta, GA, USA | | Home of Epi Info 5.0 | +--------------------------------------------------------------------+