Solved

Component based on TGraphicControl

Posted on 2002-06-27
8
467 Views
Last Modified: 2010-04-04
I wrote a small component based on TGraphicControl. For some reason however, it receives messages of the entire parent form, even if you click outside the control itself. What can I do about that? Should I base my component on another ancestor type? I considered using TWinControl, but this doesn't have a Canvas property, and I haven't got a clue on how to draw/paint a control without Canvas.
0
Comment
Question by:herr_apfelschnitt
8 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 200 total points
ID: 7115179
See http://www.experts-exchange.com/delphi/Q_20317124.html

I just posted an ewxample of how to draw on a control w/o access to it's canvas.


Good luck!!


BTW, as a rule, I would suggest NOT using TGRaphicControl for a base class of any component that you're going to want to handle messages for, since you need an HWND (handle to a window) to process messages and TGraphicControl doesn't have one. Food for thought.


GL

0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115191
Thx, i'll try it. I'll be gone for the weekend, so you'll get your points next week if it works.

Thanks again

herr_apfelschnitt
0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115194
Thx, i'll try it. I'll be gone for the weekend, so you'll get your points next week if it works.

Thanks again

herr_apfelschnitt
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 7115305
You could use TCustomControl as the base class.
It will of course depend on what you want to do.
What's your question, anyway?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:Slick812
ID: 7115433
you say
" it receives messages of the entire parent form, even if you click outside the control itself. What can I do about that?"

the TGraphic Control components I have made only get the "OnClick" OnMouseMove ect message events if the Click, Mouse move, ect. happends INSIDE the control , UNLESS you have done something to confuse the fake message events (they are fake messages because it is NOT a window control). Did you do something to get the parents onClick events?
0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115737
My question is:
I'm trying to create alternatives for TCheckBox, TEdit, TButton... All the usual GUI components... What would be the best class to derive these from? DrDelphi already explained how to draw on controls without Canvas property. I still need to try it though, and I won't be any where near a computer this weekend, so I'll have to do that next week.

I think this may be because of my older version of Delphi, but TGraphicControl doesn't seem to be able to handle events (no OnClick, OnMouseMove ... properties).
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 7115791
> What would be the best class to derive these from?
Probably TCustomControl which provides a base class for windowed controls (with a window handle).
The window handle is a must if you need keyboard focus (tabstop) for the control.
TCustomControl also provides a Canvas property.

> because of my older version of Delphi
It seems I have to ask this: What version of Delphi are you using?

> TGraphicControl doesn't seem to be able to handle events (no OnClick, OnMouseMove ... properties).
OnClick, OnMouseMove are declared in TControl already, so TGraphicControl does have them; they're just not published.

Anyway, because of the keyboard focus you should probably derive from TCustomControl.

Another option would be to use the TCustomXXX classes from StdCtrls: TCustomEdit for edit, TCustomCheckBox for checkbox etc. In this case, you'd need to override CreateParams so that the control does not create the underlying Windows standard control (see CreateSubClass).

These TCustomXXX classes implement their properties by sending appropriate messages to their window handle. Therefore you'd need to write the messages handlers, reimplementing the standard window controls.

For example, TCustomEdit.SetReadOnly(Value: Boolean) (setter for ReadOnly property) is implemented with SendMessage(Handle, EM_SETREADONLY, Ord(Value), 0);
This method is private so you cannot change it; what you can do is write your own message handler for EM_SETREADONLY to emulate behaviour of standard edit control.

HTH
TOndrej
0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7130489
Thanks to everyone else, too!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now