Adding validator symbol next to control on a Delphi form - delphi

I have an application, where there are many forms which follow visual form inheritance.
Every form has standard delphi components as well as custom components.
Form validating functionality needs to be added. That is, A small red circle or astric image needs to be drawn next to a control, if the control's value is not valid.
This drawing functionality has to be available through out the application on every control.
What is the best way of implementing this functionality? Is there any design pattern that can help?
Thanks & Regards,
Pavan.

JEDI's JVCL has the TJvValidator component that will do just that for you. Here's a link to the TJvValidators container to get you started.

Something I have done in the past in my validate method was to change the control color to $00C4C4FF for any value which fails validation, or clWindow if it passes. (I use a constant clInvalidEdit). On projects where I am also using Raize controls with a flat border, I also adjust the border to clRed. My required fields generally have a color of $00B0FFFF (again a constant clRequiredEdit).
Most often, I'll create a method named ValidateForm which returns a boolean if the form is valid, or false if its not. The validateform checks every field for validity and adjusts colors where needed, and set the active control to the first field which fails.

Related

How to implement a special indicator in a single- or multi-line edit control

I've occasionally come across examples of edit controls that have a special indicator to assist the user, like so:
and I'd like to be able to implement similar in my own code.
The screen-scrap is actually from the property editor for the TIBQuery Sql property and isn't quite what I'm after (otherwise I'd just look in the IBX code) because it disappears as soon as the user types anything. There are others where the indicator moves so as to keep its place as the user types something, but doesn't replace the caret, otherwise I'd just do that.
So my question is, how to implement a special indicator of the type I've tried to describe, that can be positioned and turned on/off in code? The simplest thing I could think of would be to somehow temporarily add a special glyph to the edit control's character set, but I have no idea how to do that, nor how to colour it differently than the control's text content.

How to prevent a firemonkey form to draw itself (for calling an own drawing function)?

I try to convert an existing OpenGL-Application from VCL-based forms to FMX-based forms in C++ Builder XE3.
For this purpose I use the handle of a Firemonkey-form to create the OpenGL device context and make this form a child of another form to mimic the panel inside the form which I had in my VCL-based application.
The problem is now that after a resize-event or in general after calling Invalidate() the form is rendered with its background. This causes a flickering or even worse: sometimes the background is shown instead of my OpenGL rendered scene.
How can I prevent the repaint of the region at the position of my Firemonkey-OpenGL-form. Alternatively, can I define an Ownerdraw-function or something else?
Please note, that it is no option for me to use a Firemonkey-3d-Form.
Have tried giving the form a transparent background? Then you can paint whatever you want 'over the top'.
The quick way is to set the forms Transparent property to True, but this creates issues with ComboBoxes.
Another way is to place a TRectangle on the form. Set it's StyleName to 'backgroundstyle'. Set it's Fill.Color to claNull. Set Stroke.Thickness to 0. This will replace the default background styling for the form.
If you want to paint your own borders too you'll need to investigate non-client area styling but I don't have a pointer to a good resource at present.
After hours of experimenting I found the solution: The "TCommonCustomForm" has the needed properties: (1) it does not draw itself, (2) it has a handle which can be used for OpenGL initialization.
I hope this information will help others.

Delphi XE2 Firemonkey - Setting the grid display colour and alignment

I am struggling to assign a style to a TGrid within Delphi Firemonkey. Styling required is quite basic (ie. Align the text in a column and colour per value).
For background, I have created a TGrid, set the rows (eg 200), and added the number of columns (3 in this case). The columns have been labeled as "Code", "Company" and "Balance". As the grid does not contain values (like a TStringGrid), I am able to set the display value via the "GetValue" method (where I retrieve data from an external source). - The result is a list that is fast, and able to cope with a lot of data, the downside is I can not format the design at run time...
I am thinking that I may have to use "Styles"; that are new in FM. If this is the case however, I am not sure how I can reference the cell as it does not really exist as it is painted via the GetValue method when it needs to be drawn?
Any help appreciated,
Regards
Ian.
Ray Konopka's blog might help you here:
http://www.raize.com/Articles/FmxStringGridCellFonts.asp
You can apply a style to a Column by creating the OnApplyStyleLookup event to the column, but to set the font style and color etc you would still need to implement a OnApplyStyleLookup for the TTextCell's themselves too.
I posted a very similar query on Stackoverflow and then found a workable solution which I added here
firemonkey mobile grid with livebindings - changing TextCell text color at runtime XE5

How make a control that look like the "download" dialog of firefox

I have a application that like firefox, can be enhanced from plugins available from internet.
Now, I want to provide in Delphi (2010) a dialog similar to the download from firefox. I have no skills in build graphical controls.
Using the standard controls of Delphi, what could be the best way... using a TListView/TStringGrid with custom draw or...
The idea is show a icon in the left, a title with subtitle with 1-3 lines on the middle and date/version on the right. That row must be selectable and that is all.
For the UI part,
The easiest way: Use TNextGrid in "Slide view" from bergsoft. It's one of my favorite VCL controls. Check this screenshot:
http://www.bergsoft.net/res/screenshots/next-grid/slides-style.gif
The most flexible way: Use TVirtualStreeTree with custom draw, but it'll take some time to get use to that most powerful tree view control and apply a custom draw.
The Most promising way: Use TMS software's advanced poly list (in beta stage currently), check the Screenshots in the following page and it's very nice looking!:
http://www.tmssoftware.com/site/advpolylist.asp
use VirtualStringTree from SoftGems.
Use TFrame to create a custom control for one download, and then reuse it.
Use a TDataSet descendant (eg. TClientDataSet, JVCL's TjvMemoryData or any other dataset you like) to have a table with all the fields needed to describe your download. For example:
Plugin_Name - Char(255)
Plugin_Icon - Blob
Downloaded_Size - Int64
Total_Size - Int64
//etc.
(Of course the above fields are provided just as an example - the actual fields are up to you).
After this, connect a TDataSource to your table and use an TDBCtrlGrid to show your data as you wish. For the above example, you can put on your record a TDBLabel, TDBImage, TjvDBProgressBar (unfortunately we don't have a data-aware gauge shipped with Delphi) etc. all these connected to the appropriate fields.
In this way you can simulate a list (if you set TDBCtrlGrid's Column property to 1) with a custom layout in which you can do select, add, delete etc.
HTH

how to set the tabwidth of the listbox portion of a TComboBox in Delphi

You can easily achieve a multicolumn effect in a listbox by setting the TabWidth property of TListbox. For example, http://delphi.about.com/cs/adptips2000/a/bltip1200_3.htm
I need to do the same in the drop down list of a ComboBox, but comboboxes don't publish any TabWidth property.
Any ideas?
In a comment to this answer advising you to owner-draw the list box items you say:
I'm wondering why I must do that when the required functionality already exists on a listbox
A combo box is actually composed of three native child windows - the combo box itself, an embedded edit, and a list box. You can use the GetComboBoxInfo() function to fill a COMBOBOXINFO structure (i.e. a TComboBoxInfo record) with information about the control, and it will return the 3 HWND elements in it. With that you are able to alter the appearance and behaviour of the list box. In principle.
For the list box to use the tab stops it needs to have the LBS_USETABSTOPS style flag set. Unfortunately this can't be turned on later, the list box has to be created with it. So you could use the functionality only if you were able to turn the style flag on for the list box, which is created during the CreateWindowEx() call for the combo box. AFAICS this can only be done by hooking the CreateWindowEx() call itself, identifying the internal call that creates the list box, and altering the passed style. This means runtime modification of code, and not in your executable but in a Windows DLL.
Owner-drawing the list items looks like it would be much easier.
From what I know there is not so simple way as TabWidth here but you can override Paint method and draw it yourself. Looking at listbox and combobox sources may help.

Resources