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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using listbox to update Db

Status
Not open for further replies.

Tracey

Programmer
Oct 16, 2000
690
NZ
Hello all

I am working on VCL development for a change at the moment. I am trying to use TListBox and getting a little lost.

I fill the listbox with items like so:

Code:
  //Run a Query, return some records
           First;
            while not eof do
            begin
                lbMapTo.Items.AddObject(FieldByName('workzonename').AsString,
                    TObject(FieldByName('workzoneid').AsInteger));
                Next;
            end;

procedure TfrmWorkZones.btnSelectOSMOSClick(Sender: TObject);
var
    i: integer;
begin
    //loop through lbOSMOS items to find the selected item.  
    for i := 0 to lbOSMOS.Items.Count - 1 do
    begin
        if lbOSMOS.Selected[i] then
            lbSelectedOsmos.Items.AddObject(lbOSMOS.Items.Strings[i], lbOSMOS.Items.Objects[i])
    end;
    lbOSMOS.DeleteSelected;
end;

My problem is, when I want to save back to the database from the “selected items” listbox, how do I cast the item’s “object” value to integer?

I must say I must be getting too used to Visual Studio, I found myself quite disappointed that I couldn’t just bind workzonename to listbox.displayfield and workzoneid to listbox.valuefield

Perhaps I am going totally the wrong way? Any advice before I waste too much time on this?

Cheers

Tracey


Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Why don't you use a dbListbox instead, that way the listbox is bound to the datafield.

Steven van Els
SAvanEls@cq-link.sr
 
I had some problems trying to use that with my query. I have got this problem sorted now.

ID := Integer(ListBox.Objects);

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top