Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2018, 08:19 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 280
Default Delphi5: Change the Background Color of TEdit

Dear Expert,

I am working on a Delphi5 project. I need to change the Background color of TEdit component on its Entry. Once the Cursor enters the TEdit component, the color should change to say clAqua and once the cursor exit, the color should change to default clWindow. I do not want to code on OnEntry and OnExit event for each component. Kindly suggest me a code that work for all TEdit component in a project.

Thanks in advance.
__________________
Rmt
Reply With Quote
  #2  
Old 03-21-2018, 08:47 PM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 27
Default

ComCtrls contains RichEdit, RichEdit contains TTextAttributes

You can ether install TTextAttributes to TEdit or use RichEdit and override events.
Reply With Quote
  #3  
Old 03-22-2018, 05:42 AM
rmt rmt is offline
Senior Member
 
Join Date: Jun 2013
Posts: 280
Default

Dear lex,

Thanks for the suggestion. Can u please elaborate a bit more? Please provide me a code to override events.

Regards,
__________________
Rmt
Reply With Quote
  #4  
Old 03-22-2018, 07:40 AM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 27
Default

look up the RichEdit in Delphi and you will find TTextAttributes

and install on your Edit as a descendant with example rich edit

Or control mouse, kebourd events in richedit to look like TEdit

that is your choice, or look up torry pages or something
some one may have made one
Reply With Quote
  #5  
Old 03-22-2018, 08:33 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,305
Default

Make your own TEdit descendant in a new unit, but still name it TEdit.
Make sure in the forms where you want to use this it's unit is found BEFORE the original unit where TEdit lives in.
In this own component implement the OnEnter/OnExit as you see fit and all would be fine without doing all that much code
Reply With Quote
  #6  
Old 03-22-2018, 12:04 PM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 27
Default

Never reuse a name in Delphi
that's a no every time. Give it a simple change TSEdit is enough
Or you will have conflicts with other objects from the TEdit Unit File
TComboBox, or TTabs
If you cannot build it your self USE Rich edit and heavily add code to control the events.
Disadvantage lots of code in your main file.
Reply With Quote
  #7  
Old 03-22-2018, 01:33 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,305
Default

I disagree on this point, especially for what the TS wants.
you can build your own component and give it your own name, but in this case the TS should replace all TEdit with TSEdit (your example) and as for mine it's only a matter of adding a unit to the uses.

The RichEdit is a very bad solution for what the TS wants, it's just a lot of overhead for something that could be easily solved by just adding the OnEnter OnExit events. If you don't want to add this to each TEdit control (because that's the only thing the TS asks for!!!) you could also do dynamic binding of an already build OnEnter/OnExit (for example in the OnFormCreate loop through the components, if TEdit then TEdit(Component).OnEnter := MyEditEnter)

My solution is the easiest, with the least overhead and I've never, but absolutely never, had any conflicts what so ever. And yes, I've used this a lot in 1 project, just because it was the easiest solution without modifying each frm with my own component. And why do you think it conflicts with TComboBox?
I would say you're just reacting to something that you didn't know and shoot it down before testing it properly.

I'm really curious on what your solution would look like, especially your RichEdit solution, which also should be an own component since by default it doesn't support background color change in OnEnter/OnExit.
And also what conflicts you get with my solution...
Reply With Quote
  #8  
Old 03-27-2018, 10:35 AM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 27
Default

TTextAttributes is back ground support, the best you can have in windows
Reply With Quote
  #9  
Old 03-27-2018, 12:56 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,305
Default

And TRichEdit is a Delphi component, which has it's own implementation. So you throw out a lot of your own argument if you want it to be as close to windows as possible. This component is not a native windows component.
I really don't like the TRichEdit component, so I am just curious how it is that you are. Perhaps I then reconsider and replace all my TEdit components, who knows...

But that all aside, you still haven't answered my questions. You just keep throwing back at short unfounded statements. Be a big boy and back them up.
Not just to please me, perhaps I have it all wrong, but you're so stuck at this TRichEdit that I would like to see how your solution would look like. And the answer that TTextAttributes is the way to go is not an answer to this question. Some small coding sample would be nice, because I'm having trouble placing this solution in what the TS wants...

And you where very strong against my solution, so I just asked what conflicts you think you encounter.

So I hope that you give your take on all this (and then not only the part where TRichEdit is just the best component Delphi has, but also the questions in my previous post).
Reply With Quote
  #10  
Old 03-27-2018, 06:41 PM
lex lex is offline
Junior Member
 
Join Date: Feb 2012
Posts: 27
Default

TRichEdit true is not strictly native Delphi as it has heavy dependence on special windows dll's to work. So is TTextAttributes messages to control color around fonts is way superior than using Delphi's TFont that everything else in Delphi depends on TFont. Even in c++ the TTextAttributes messages
TFont is outdated before it was created in Delphi because of bad foresight of the developer.

Some of your comments lack OOP experience over simple things like naming in Delphi that creates so many critical identity clashes in a end product executable. This is basic OOP experience with the Delphi compiler.

Yes I do have two major near professional objects up and running that have needed some redesign and are not perfect (hints not working currently). They present them selves very well to the end user and are easy to code to. producing a near professional *.exe product that I'm still working on.
I have had my problems - true, their would be many that use this form that wish they could do what I do.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:33 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.