Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: GetWindowRect parameters

48 views
Skip to first unread message

Avatar Zondertau

unread,
Aug 14, 2004, 5:15:36 AM8/14/04
to
> I dont understand why I cant compile this
>
> var
> hnd: thandle;
> r: trect;
> begin
> GetWindowRect(hnd, @r);
> end;
>
> What are the good parameters?

GetWindowRect(hnd, r);

Instead of being declared as a pointer the second parameter is
implicitly passed by reference by marking it 'var'. This makes you have
to wory less about pointers and makes the code more readable.
Unfortunately this is not done constently (because in some cases you
have to be able to pass nil) so you will have to check it for evey
parameter of every API function you call.

jef

unread,
Aug 14, 2004, 5:46:33 AM8/14/04
to
thanks, but sorry: it does not compile more.
the error message is allay:
'Les types des parameters VAR originaux et formels doivent etre identiques"

greybeard

unread,
Aug 14, 2004, 8:13:05 AM8/14/04
to

I've tried it, and I've got only warning "hnd might not have been
initialized".
But really, try to change declaration to "var hnd: HWND;"
It's the same, but compiler will better understand :-)

Vlastik

"jef" <jf.j...@opales.fr> píse v diskusním príspevku
news:411DDF79...@opales.fr...

Peter Below (TeamB)

unread,
Aug 14, 2004, 12:22:15 PM8/14/04
to
In article <411DDF79...@opales.fr>, Jef wrote:
> thanks, but sorry: it does not compile more.
> the error message is allay:
> 'Les types des parameters VAR originaux et formels doivent etre identiques"

This means that you have redeclared the TRect type somewhere. It is already
declared for you in the Windows unit, if you have an alternate declaration
somewhere else (even if it is totally identically to the one in Windows.pas)
you have two different type that cannot be interchanged in situations
requiring type identity (like passing to a Var parameter that expects to get
a Windows.TRect).

To find the offending declaration, hover the mouse over the "TRect" in your
variable declaration. The IDE should show a hint with the location of the
declaration. To resolve the conflict (if you cannot remove the duplicate
type) you can declare your parameter as

r: Windows.TRect;

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


jef

unread,
Aug 17, 2004, 2:22:54 AM8/17/04
to
Ok, but it is not the reason
In a new application, just with a button where I only have GetWindowRect(hnd,
@rect); I cannot compile , always with the same message, and with many API
functions where Pointer on tRect is needed.
I did the test on 2 pc one with Win2000 and one with WinXP. Strange


I just want to know if an other application is runing and if so where is it on
the desk.
Is there other way to do that?

By the way, in windows.pas source file, just after HiByte function, there are
many blank lines in Type declaration; I reload my source cd distribution, but it
is the same (delphi 7 pro); perhaps some declaration are missing ?

In any case Thanks for your help


Peter Below (TeamB)

unread,
Aug 17, 2004, 11:59:46 AM8/17/04
to
In article <4121A43E...@opales.fr>, Jef wrote:
> In a new application, just with a button where I only have GetWindowRect(hnd,
> @rect);

You are calling the function the wrong way. Try

GetWindowRect( hnd, Rect );

When it doubt check the translation of the API function in the Windows unit. In
may cases Borland decided to convert pointer-to-things parameters to Delphi Var
parameters, which allow you to skip all the pointer stuff. More natural to a
Pascal programmer but a potential trap if you work with the API help and ignore
the code completion parameter hints <g>.

0 new messages