Jump to content
Sign in to follow this  
karl Jonson

comma separated values in DBEdit

Recommended Posts

I have a DBEdit linked to a integer-field in a table & everything works fine but now I'd like to allow user to enter many integers separated by commas in the DBEdit.
So when user types 1,2,3 three records are inserted in the table & without the posting failing.
How can I achieve this ?
TIA

Share this post


Link to post
17 hours ago, karl Jonson said:

I have a DBEdit linked to a integer-field in a table & everything works fine but now I'd like to allow user to enter many integers separated by commas in the DBEdit.
So when user types 1,2,3 three records are inserted in the table & without the posting failing.
How can I achieve this ?
TIA

Not with a TDBEdit. Databound controls are typically linked to one single record (the  current record in the dataset); using them the typical workflow is: add new record - enter data for this record - post the record to the dataset.

 

You have to use an unbound TEdit in your case and dissect its content in code, e.g. when the user leaves the control (OnExit event), or when he pushes a button.

 

Pseudo code:

var
  LList: TStringlist;
  N, LValue: integer;
begin
  LList := TStringlist.Create;
  try
    LList.StrictDelimiter := True;
    LList.Commatext := Edit1.Text;
    for N:= 0 to LLIst.Count - 1 do begin
      if TryStrToInt(Trim(LList[N]), LValue) then begin
        add record to dataset
        store LValue into the dataset field
        post the record 
      end; {if} 
    end; {for}
  finally
    LList.Free;
  end;
end;    

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×