TValueListEditor with more columns - delphi

I'm using a TValueListEditor and i would like to make an IDE property editor like.
Each line can have few kinds of informations :
String
Date
Number
ComboList
I'm wondering how can i store the type of element and the format for each line.
I try to add 2 columns. But its not working
ValueListEditor.ColCount := 4;
ValueListEditor.Cell[4,2] := 'Test';
It shows the value Test in the value column (the second column instead of 4).
I was thinking to embeded the values that i need in an object that i will link (add) to each line. But i didnt' find the way to do so. Even i don't know if it's possible.
Does anyone have an idea ?

TValueListEditor is specifically designed to handle name=value pairs only. You can't add additional columns to it. However, you can specify the type of editor used for editing the value column. That is handled by the TItemProp.EditStyle property for each pair:
For String input, set the TItemProp.EditStyle to esSimple.
For ComboList input, set the TItemProp.EditStyle to esPickList, and then use the TItemProp.PickList property, or the TValueListEditor.OnGetPickList event.
For Numeric input, set the TItemProp.EditStyle to esSimple, and set the TItemProp.EditMask and TItemProp.MaxLength as needed. You can then convert the user's entered value to an Integer when needed.
For Date input, you are best off setting the TItemProp.EditStyle to esEllipsis and then use the TValueListEditor.OnEditButtonClick event to display your own TForm that has a TDateTimePicker on it. You could do something similar for numeric input if desired, using a TSpinEdit or similar component.

Related

Get a Text data type in stored procedure

I need to have a Text data type column (instead of an Lvarchar, for space reasons) in a table. But I have a problem. If I pass the insert/select statement from C#, with the parameter being a string, the connector will do the type conversion automatically and everything works fine.
But I want to have it on a stored procedure. Although, it doesn't let me:
have a Text data type as an input parameter;
have load/unload statements in a stored procedure (that way I could just pass the string and unload and then load it to the table);
can't seem to make a data type conversion in informix...
So... Given this situation, how can I possibly do this? I'm aware that a Text data type is hell to work with but it's also great for saving storage space and not pre-setting a size limit. Correct me if I'm mistaken, as I'm new to Informix.
In this case, I just need to save text (which may or may not be big/small) and return it when needed. Don't need to work it in any way other than that.

lazarus - TMemo text property

I am using a TMemo box intead of a TEdit box simply because of the multi-line ability.
I was guessing and I used the .Text property to assign a value at run-time. But then I realised that there was no Text property at design time. Rather I found the Lines property.
I checked this page: http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tmemo.html for more info.
I found out that there is no Text property but only a Lines property in that documentation.
Is my use of .Text correct or is it a problem using this?
Here's my code:
if dlgSave.Execute Then
begin
txtSaveName.Text := dlgSave.FileName;
end;
txtSaveName : TMemo
dlgSave : TSaveDialog
Thanks for any inputs.
Lines is a TStrings, a class that is basically a wrapper for an array of strings.
Text is a simple property that when read concatenates the strings together (with lineseparators between them), and when assigned too parses the single string into multiple strings.
I wouldn't worry too much about it, just think twice before using it for huge strings (think hundreds of MBs and bigger), since all the copying done by this highlevel functionality will eat quite some memory.
Another (minor) reason not to use it is if you want reading and writing to be binary the same. Assume you have a text with mixed line endings and you assign it to text and read it back, then the mixed lineendings will be uniform now.

How to change time in DBEdit bounded to DateTime Field to military time format like ' 2300'?

I'm using Delphi XE3 and XE2
I have a TDBEdit which is bounded to a TDateTime field in my database.
My TDBEdit should display the time in military format which is 2300
but it's currently displaying the regular time 10:05:00 AM
I've tried to set the input mask to something like !9000 but it gave me: 00 AM
I've checked all possible ways with the input mask with no use.
Is there anyway to get over that ?
Also I cannot see the Data.DB.TDateTimeField.DisplayFormat property anywhere
Not here either
You can't see them because you're trying to do it wrong, as Uwe said.
Create a persistent field (double click your table or query, and add a field for the TDateTime field), and then use it in your code. Here's one for a plain TTable (actually a TADSTable from Advantage Database) with a TDateTimeField called DATE_OPEN:
If you don't want to create persistent fields, you can always just typecast (make sure it's an actual TDateField if you do so, or you'll end up with an access violation). Also note that there are two ) characters before the dot .. The left one closes the FieldByName function call, the second completes the typecast to TDateField, and both have to be there in order for this to work.
You can then set the DisplayFormat to hhnn to accept times like 0900 or 2100 for 9:00 AM or 9:00 PM respectively.
The correct entry for the fields DisplayFormat property is "hhnn".

Using .AsString or .Text?

I have just seen a bit of code (D5) where they used...
aStr:=tblAcct.FieldByName('Name').Text;
It seems to work fine but I have always used...
aStr:=tblAcct.FieldByName('Name').AsString;
I have used both when loading a TMemo and again there seems no difference.
aMemo.Lines.Text:=tblAcct.FieldByName('History').Text;
aMemo.Lines.Text:=tblAcct.FieldByName('History').AsString;
Is there a reason why I should use one over the other?
If so, which one?
Actually for TMemo, I usually use...
aMemo.Lines.Assign(tblAcct.FieldByName('History'))
which seems to work fine too.
Thanks
The Text property is meant to be used to obtain the textual representation of a field being edited in a DataAware control, in contrast with the DisplayText property that gives you a string to represent the value to the user (it may contain punctuation or other decoration to the plain value).
Contains the string to display in a data-aware control when the field is in edit mode
A typical example is a TFloatField with the Currency property set to True. The DisplayText gives you a string with the number containing commas (if needed), the decimal separator and a currency symbol. The Text property gives you a string without commas or currency symbol.
begin
MyFloatField.Currency := True;
MyFloatField.AsFloat := 1234.56;
A := MyFloatField.Text; //'1234.56'
B := MyFloatField.DisplayText; //'$1,234.56', depends on your locale
end;
Both above properties can be customized writing a OnGetText event handler where you can write custom logic to convert the value to a string representation. The DisplayText parameter indicates if the wanted string is meant to represent the value for edit or not.
On the other hand, the AsString property uses a more plain conversion between the base data type and string. Each TField descendant implements the virtual GetAsString method using functions from the RTL to perform that representation. Following the TFloatField example, this class calls FloatToStr() for that purpose.
All this said, the answer to your question is: AsString returns the same string as the Text property if there's no OnGetText event handler, but it may be different if there's a event handler or a non-standard TField descendant.
I can't tell what is more appropriate for you, because it depends on what's the intended use for the returned value, but if you're using it to display the values to the user in the UI (as your code example), I advise you to use the DisplayText property.
AsString contains field's value as string.
Text contains the string to display in a data-aware control when the field is in edit mode.
So in your case I think you should use AsString.

Delphi TDataSet filter case insensitive not working

I have an application with lots of datasets created at run-time. Some of this datasets are filtered. As filterOptions I've set foCaseInsensitive
dataset.FilterOptions := [foCaseInsensitive];
that means that 'foCaseInsensitive - Ignore case when comparing strings. ' according to Delphi help.
The dataset.filter is changed on user input.
At begging it shows all values:
when user type something is changed:
The problem is that when I'm typing the last character, it shows nothing
Problem does not appear when I'm typing on upper-case
how can I fix this, to show correct the values when user input is only in lower case?
LE: the component is a standard TDataSet from Delphi.
Filter is assigned with 'Like %value_entered%'.
LE1: I'm using a in-house component which has a DataSet property. After I'm setting the filter, I set the property Filtered to true. So, it is a TDataSet property on what I'm talking about.

Resources