Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Pos


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Mar 8, 2017 2:48 AM Last Post By: Melissa Torn
Melissa Torn

Posts: 143
Registered: 4/30/09
Pos  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 24, 2017 1:58 AM
I have a DBComboBox
It looks like below
1-AA
2-BB
This DBComboBox's Data Field is Integer
so when a user select any item from the DbComboBox
I need to write just first number of the selected item
for example just 1 or just 2
DBComboBoxClick event is like below
iPos := Pos('-',TDBComboBox(Sender).Text);
Str := Copy(TDBComboBox(Sender).Text, 1, iPos-1);
MyDataset.FieldByName('IntegerField').asString:=Str;
After selecting an Item from the dbcombobox list
My Field is still blank, nothing happens, what is wrong ?

Thank You
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Pos  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 25, 2017 1:01 AM   in response to: Melissa Torn in response to: Melissa Torn
Melissa Torn wrote:

I have a DBComboBox
It looks like below
1-AA
2-BB
This DBComboBox's Data Field is Integer
so when a user select any item from the DbComboBox
I need to write just first number of the selected item
for example just 1 or just 2
DBComboBoxClick event is like below
iPos := Pos('-',TDBComboBox(Sender).Text);
Str := Copy(TDBComboBox(Sender).Text, 1, iPos-1);
MyDataset.FieldByName('IntegerField').asString:=Str;
After selecting an Item from the dbcombobox list
My Field is still blank, nothing happens, what is wrong ?

Thank You

Have you verified (in the debugger, by setting a breakpoint on the
first line of the code you showed) that

1. the code is executed (the breakpoint is reached)
2. str is not empty before you assign it to the field
3. the dataset is in edit mode
?

--
Peter Below
TeamB

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Pos  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 25, 2017 2:07 AM   in response to: Melissa Torn in response to: Melissa Torn
Melissa

I haven't used a DBComboBox for ages but what you seem to be trying to do is fight what it should be doing. Change a DBComboBox and it changes the linked field in the table to whatever item is selected. Since this is an integer field and you have a none integer value it will leave it blank. If you use a simple conbobox and manage its relationship with the table yourself it will be easier.

Then again, as I said, its been ages since I used a DBComboBox I could be wrong.

Roy Lambert

Cristian Peța

Posts: 157
Registered: 8/7/06
Re: Pos  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 25, 2017 12:30 PM   in response to: Melissa Torn in response to: Melissa Torn
I would fill the DBComboBox.Items with what the db field expects (1 and 2) and use OnCustomDraw to show to the user a human readable text.
Melissa Torn

Posts: 143
Registered: 4/30/09
Re: Pos  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2017 2:48 AM   in response to: Melissa Torn in response to: Melissa Torn
Thank you Peter, Roy, Cristian
Sorry for late respond, i was seek for few days.
I think it is impossible to do this with a DBComboıBox
so i changed my algortim.

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

Server Response from: ETNAJIVE02