Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to check Active Control edtable



Permlink Replies: 8 - Last Post: Mar 1, 2018 2:09 AM Last Post By: Roy Lambert Threads: [ Previous | Next ]
Kent Foong

Posts: 36
Registered: 8/1/00
How to check Active Control edtable
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 12:24 AM
Is there a way that I can check if the activecontrol an editable control like tedit, tmemo etc or non editable control like tbutton, tradiobutton etc?

thanks
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: How to check Active Control edtable
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 12:26 AM   in response to: Kent Foong in response to: Kent Foong
Kent Foong wrote:

Is there a way that I can check if the activecontrol an editable control like tedit, tmemo etc or non editable
control like tbutton, tradiobutton etc?

You could do a check like:

  if (ActiveControl is TEdit) or (ActiveControl is TMemo) {etc} then
    // Whatever


--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to check Active Control edtable
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 9:27 AM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:

You could do a check like:

  if (ActiveControl is TEdit) or (ActiveControl is TMemo) {etc} then
    // Whatever

TEdit and TMemo both derive from TCustomEdit:

if ActiveControl is TCustomEdit then
begin
  // ...
end;


--
Remy Lebeau (TeamB)
Kent Foong

Posts: 36
Registered: 8/1/00
Re: How to check Active Control edtable
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 6:50 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Dave Nottage wrote:

You could do a check like:

  if (ActiveControl is TEdit) or (ActiveControl is TMemo) {etc} then
    // Whatever

TEdit and TMemo both derive from TCustomEdit:

if ActiveControl is TCustomEdit then
begin
  // ...
end;


--
Remy Lebeau (TeamB)

I am try to avoid this kind of checking because I will need identify each and every control I am using in my project, some of the thirdparty control might not be TCustomEdit descendant. Or, is that a must for all editable controls to be inherited from TCustomEdit?

I found TCombobox is not inheriting from TCustomEdit, but it is editable.

One thing for sure is, those editable control has got caret showing when in edit mode, is there a way to check from this direction?

Thanks

Edited by: Kent Foong on Feb 27, 2018 6:55 PM
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: How to check Active Control edtable [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2018 7:20 PM   in response to: Kent Foong in response to: Kent Foong
Kent Foong wrote:

I am try to avoid this kind of checking because I will need identify each and every control I am using in my project,
some of the thirdparty control might not be TCustomEdit descendant. Or, is that a must for all editable controls to
be inherited from TCustomEdit?

I found TCombobox is not inheriting from TCustomEdit, but it is editable.

I don't think you have any other choice than to identify which controls are editable - there's no special requirement
to descend from a particular control.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: How to check Active Control edtable [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2018 12:44 AM   in response to: Kent Foong in response to: Kent Foong
On 2/27/2018 9:57 PM, Kent Foong wrote:
Remy Lebeau (TeamB) wrote:
Dave Nottage wrote:

You could do a check like:

   if (ActiveControl is TEdit) or (ActiveControl is TMemo) {etc} then
     // Whatever

TEdit and TMemo both derive from TCustomEdit:

if ActiveControl is TCustomEdit then
begin
   // ...
end;


--
Remy Lebeau (TeamB)

I am try to avoid this kind of checking because I will need identify each and every control I am using in my project, some of the thirdparty control might not be TCustomEdit descendant. Or, is that a must for all editable controls to be inherited from TCustomEdit?

I found TCombobox is not inheriting from TCustomEdit, but it is editable.

One thing for sure is, those editable control has got caret showing when in edit mode, is there a way to check from this direction?

Thanks

Edited by: Kent Foong on Feb 27, 2018 6:55 PM

You can set the tag of the control to say 1 is editable if you don't want to
manually check for each type you might have on the form.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)
Roy Lambert

Posts: 40
Registered: 10/21/99
Re: How to check Active Control edtable
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2018 1:40 AM   in response to: Kent Foong in response to: Kent Foong
Kent

I agree with the other posters - you have little option other than to mark each editable control (say by setting the Tag) as you add it to a form or create a small function to check against a known list of control classes.

No-one else has asked yet - why do you want to do this? I ask because there may be a way of doing what you want.

Roy Lambert

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to check Active Control edtable
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2018 8:55 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:

No-one else has asked yet - why do you want to do this? I ask because
there may be a way of doing what you want.

One way would be to define a custom interface, then derive new controls
that implement that interface. Even interposer classes will suffice.
Then, at runtime, you can simply query if the ActiveControl implements
that interface or not.

--
Remy Lebeau (TeamB)
Roy Lambert

Posts: 40
Registered: 10/21/99
Re: How to check Active Control edtable
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 1, 2018 2:09 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy

Your approach is possible but is almost certainly more effort than a simple function testing the class.

Roy Lambert

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02