?
Solved

Finding a components ACTUAL LEFT&TOP..

Posted on 1999-12-13
20
Medium Priority
?
147 Views
Last Modified: 2010-08-05
Howdy,

I have a program in which I have a control bar, on which is a drop down tool button. When someone clicks the little down arrow it pops up my popup menu for people to select from.  The first time someone clicks the button itself, it also needs to drop that popup button down.  Which is easy enough;
Menu.Popup(x,y);

The problem I am having is getting my popup menu to appear right below the control.  I need to be able to find the correct x,y of the drop down tool button. Because it is on a control bar, which can be anywhere on the application, the drop down tool buttons top and left are 0.  (it is the left top most control on the control bar).

How do I find the Top and Left of the drop down tool button relevant to the screen?  Being that the 0,0 is the upper left-hand corner of the screen...

Hope I explained that well enough..

Thanks..
-Jason
0
Comment
Question by:Palamedes
  • 9
  • 6
  • 4
  • +1
20 Comments
 
LVL 10

Accepted Solution

by:
ptmcomp earned 60 total points
ID: 2278006
var
  TopLeft: Point;
begin
  TopLeft:=ClientToScreen(Point(MyControl.Left, MyControl.Top));

I hope that'll help you.

Regards, ptm.
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278060
That doesn't seem to work. I am still playing with it to try to get it to though.

-Pal
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2278087
hi pal,

what ptmcomp has suggested should work

try my simple sample
(drop a popupmenu and a button on a form,
define at least onemenu-item for the popupmenu)

procedure TForm1.Button1Click(Sender: TObject);
var P : TPoint;
begin
  If (Sender is TButton) then
  Begin
    P := ClientToScreen(PoinT(TButton(Sender).Left,
                              TButton(Sender).Top+
                              TButton(Sender).Height));
    PopupMenu1.PopUp(P.X,P.Y);
  end;
end;

meikl
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Author Comment

by:Palamedes
ID: 2278141
I tried it on a blank form and it worked just dandy.. but when I place it in my program using a TToolButton it doenst work.. However, a blank form with a TToolButton DOES  work... *sigh*  what do you think is the reasoning.. ?


procedure TForm1.RacesBoxClick(Sender: TObject);
var P : TPoint;
begin
  If (Sender is TToolButton) then
  Begin
    P := ClientToScreen(PoinT(TToolButton(Sender).Left, TToolButton(Sender).Top+TToolButton(Sender).Height));
    RacesMenu.PopUp(P.X,P.Y);
  end;
end;
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278150
The error message I am getting is ;

[Error]Unit1.pas(542); ')' expected bu ',' found

And its refering to this line,

P := ClientToScreen(PoinT(TToolButton(Sender).Left,

with the curser there after the Left,

This is a cut and paste of the EXACT same code I used in a blank form and it worked like a charm..

any ideas?
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2278165
This is what you want I think.

pt := MyControl.ClientToScreen(Point(0, 0));
Menu.Popup(pt.x, pt.y);

Cheers,
Phil.
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278185
The error message I am getting is ;

[Error]Unit1.pas(542); ')' expected bu ',' found

And its refering to this line,

P := ClientToScreen(PoinT(TToolButton(Sender).Left,

with the curser there after the Left,

This is a cut and paste of the EXACT same code I used in a blank form and it worked like a charm..

any ideas?
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278198
Phil,

I am getting the same error.

P := RacesBox.ClientToScreen(Point(0, 0));

is the line, and after the first 0, I get a ')' expected but ',' found.

Its as if it thinks POINT only has one argument..


Grrrr.. this may be a bug of the D5 demo.  Good thing the real version will be here tomorrow..

-pal
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2278204
The reasoning is that a controls top and left is relative to it's parent, not the form.

Try my suggestion.

Cheers,
Phil.
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2278217
Make sure Classes comes after Windows in the uses clause.

Cheers,
Phil.
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278223
I think this must be some sort of bug.  I am cutting and pasting these examples from a blank form to my form and it works in the blank form.  

the difference between "Myform" and the blank one are nil..

Again, I am using the demo version of D5 until my bought copy arrives.. I think its just buggy.

-Pal
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278228
"Make sure Classes comes after Windows in the uses clause. " 

It does.

-Pal
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2278236
Have you delcared some variables or procedures named Point?
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2278243

0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2278250
You could also write
var
  r: TRect;
  pt: TPoint; // Was my bug has to be TPoint instead of POint
begin
  Windows.GetWindowRect(MyControl, r);
  pt:=r.TopLeft;
  Menu.Popup(pt.x, pt.y);
end;
 
Regards, ptm
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278262
Okay.. I moved Classes to the very end of my Uses clause and it works like a charm now..

But I don't understand why...

Here is my Uses line

uses
  Windows, Messages, SysUtils, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, Buttons, ComCtrls, Menus, ToolWin, ImgList,  StdCtrls,
  SHDocVw, Classes;


Classes WAS after Controls, and it didnt work.. its not at the end and works..

can someone explain that? (and who should I give these points to?)

-Pal

(thanks everyone.. )
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2278263
Point is a function declared in Classes.pas.

function Point(AX, AY: Integer): TPoint;

You can do this instead (same result).

>>>>>>>>
var
  P: TPoint;
begin
  P.x := 0;
  P.y := 0;
  P := RacesBox.ClientToScreen(P);
  Menu.Popup(P.x, P.y);
end;
<<<<<<<<<

Cheers,
Phil.




0
 
LVL 3

Expert Comment

by:philipleighs
ID: 2278278
The explanation.

Point is a windows type, as well as a function.

The compiler uses the last version of the type it sees in the uses clause.

Cheers,
Phil.

PS: There has been some serious overlap here! Check the times!  :-)
0
 
LVL 4

Author Comment

by:Palamedes
ID: 2278301
heh, yeah I noticed the overlap.. I like a quick response though.. its handy..

Not sure who to give the points to though.. everyone was helpful.  Especially you Phil.. but I am going to give the points to PTMComp as he was the first to answer correctly.. It was just a matter of figuring out the Classes bit afterwards..

Thanks Everyone

-Pal
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2278329
Thanx. #;o)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question