Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing numeric format in a Spinedit component 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I am using a serial device to input data in some Spinedit component. The format in the spinedit is 0.00
The thing is that when i use the input device via the serial port, i get a format of 000. I do not get the period added.
I can find out when a value is inputed in the spinedit but need a way to change it before i tab to go to the next spinedit.

For example, i have a value of 016 inputted. it spinedit but when i press enter or tab to validate, i want it to change to 0.16

Can it be done?
Thanks for any help..
Sincerely,
P
 
The OnExit event could be used for this. But what control are you using for your spin edit? I don't see how to get a decimal value into the standard Delphi control.
 
Sorry, i forgot to mention it is a devexpress spinedit where i can have a float value. My apologies.
Yes, i am aware of the onexit event. I just would like to know if it is possible to change a 000 format to a 0.00 format.

Thank you..
 
I've stored the value in the cxSpinEdit's .Tag property so that I didn't have to worry about reading from the spinedit.value when it came time to save the data.

Code:
procedure TForm24.cxSpinEdit1Enter(Sender: TObject);
begin
    cxSpinEdit1.Value := cxSpinEdit1.tag / 100;
end;

procedure TForm24.cxSpinEdit1Exit(Sender: TObject);
begin
    cxSpinEdit1.Value := cxSpinEdit1.Tag;
end;

procedure TForm24.cxSpinEdit1PropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
    cxSpinEdit1.Tag := (DisplayValue * 100);
end;


procedure TForm24.FormCreate(Sender: TObject);
begin
    cxSpinEdit1.Properties.EditFormat := '0.00';
    cxSpinEdit1.Properties.DisplayFormat := '000';
end;
 
Oh, i see..Dividing by 100. Very smart. Why is displayformat 000. I would like to have it displayed as 0.00
Now when i input the value, it goes directly into the cxspinedit. I guess i do not have to use your enter event. am i correct.
When the value is automatically entered in the cxspinevent, the validate and exit command are triggered in that order. Am i also correct?
Thanks.
P
 
OnValidate can also be triggered my pressing enter unless you turn that properly off. You'll probably want to turn it off for this to work.

Yes - OnValidate is fired before you leave - you can set an error message if you want which will prevent the focus from leaving the field.
 
when a value is entered by the input device, i send a tab command after that to go in the next cxspinedit.
could you explain why you set the displayformat to 000 and not 0.00?
thanks.
 
Well, i guess i am a numb nut but i cannot get it to work. manually i enter 016 in the spinedit and press the tab key. Depending on how i change the displayformat, I either get 3 or 300 but not 0.16.

Thanks
P
 
Ok, i am getting there. I found out that the 3 was the max number i set it to...

this is what i have:
procedure TFrm_Tonal.Square001Exit(Sender: TObject);
begin
Showmessage(floattostr(Square001.editValue));
end;

procedure TFrm_Tonal.Square001PropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
Square001.editValue := DisplayValue /100;
Showmessage(floattostr(Square001.editValue));
end;

If i enter 016 in square001, the validate message shows 0.16. Perfect.

Now the onexit event shows 16. why?
Both my displayformat and edit format are 0.00.

Any idea...
Thanks.
 
Ok, i think i am going to give up on this one. Everything works but when you click back in the spinedit, it changes is format !!!
it is showing 0.16 and it's perfect. If i click back inside it switches to 16.00

This is the code i am using and both editformat and displayformat are 0.00

procedure TFrm_Tonal.Square001Exit(Sender: TObject);
begin
Square001.Value := Square001.Tag / 100;
end;

procedure TFrm_Tonal.Square001PropertiesValidate(Sender: TObject;
var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
Square001.Tag := DisplayValue;
end;

the value entered is 016. then i press tab, it does show 0.16 but when i click back inside, it goes to 16.00 !!!
 
Oh - you probably want your value type to be float - not integer.
 
it is float !!! what is what i do not understand..it has to do with some kind of display property that i cannot figure it out.
if i have a cxspinedit with no event and i enter 0.16, not 016 then it will be fine. now if i have the event to modify the 016 to 0.16, it will display fine until i click back in the cxspinedit and it changes to 16.00

What the heck ?
 
Here's all the properties of my TcxSpinEdit:
Code:
  object cxSpinEdit1: TcxSpinEdit
    Left = 126
    Top = 30
    Properties.Alignment.Horz = taRightJustify
    Properties.DisplayFormat = '0.00'
    Properties.Increment = 0.010000000000000000
    Properties.ValueType = vtFloat
    Properties.OnValidate = cxSpinEdit1PropertiesValidate
    TabOrder = 0
    OnEnter = cxSpinEdit1Enter
    OnExit = cxSpinEdit1Exit
    Width = 67
  end
 
thanks man...setup my cxspinedit or it is really a cxdbspinedit the way you have it and it still shows 16.00 when i enter 016.
it has to do with the computation or something.
i found a way around.
i use a cxspinedit instead of a cxdbspinedit.
i enter 016 and post the resulting value in the database. in the onexit event, i read back the value from the field and display it in the cxspinedit.
that works..
the weird thing is that if a use a plain cxdbspinedit with no event and i key 0.16, it will stay at 0.16 and does not change to 16.00.
appreciated all your patience with me. i can live with the workaround.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top