Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2018, 04:38 PM
durbslaw durbslaw is offline
Junior Member
 
Join Date: Jun 2018
Posts: 2
Smile Listbox index value and Dynamic TEdit text

Hello Forum,


Please help with...THANK YOU!!!


I have a panel pnlOrdDet which resides on a form frmSalesAgentTasks. The objective is to capture from the panel values into the database.The OrdDetID drop down list is populated with a SQL query that retrieves values in the Orders table but not in the Orderdetails table. Once populated the Products which relate to the OrderID can be selected from a multivalue listbox, the Quantity and Discount values related to the order are Dynamic TEdit components that are generated at runtime when the pnlItems or pnlDisc panels are clicked (calls an OnCLick procedure to generate the number of Edits dependent on the listbox selection), once all fields are inputted you can then add the record to the DB.

I have 2 major hurdles here, the first is on the lstUnitPrice listbox which is supposed to populate the listbox based on the number of items selected in
the lstProdOD listbox, the code below produces the correct number of lstUnitPrice entries but all have the same value (the equivalent value of the last selected lstProdOD )

procedure TfrmSalesAgentTasks.lstUnitPriceODClick(Sender: TObject);
var
ItmIndx : string;
l : integer;
begin
for l := 1 to lstProdOD.SelCount do
begin
with ADOQuery5 do
begin
close;
sql.clear;
ItmIndx := lstProdOD.items[lstProdOD.ItemIndex];
sql.text :='select UnitPrice from Foyb_Products where ProductID = ' + ItmIndx;
Open;
ADOQuery5.first;

while not ADOQuery5.eof do
begin

lstUnitPriceOD.items.Add (ADOQuery5['UnitPrice']);

ADOQuery5 .next;
end;
end;
end;
end;

********
Panel with dynamic TEdit component
************

procedure TfrmSalesAgentTasks.pnlEnter(Sender: TObject);
var
itemCount,j,k: integer;

begin
j:=1;
itemCount := lstProdOD.selcount;
showmessage('Item Count' + '' + IntToStr(lstProdOD.selCount));
for k := j to itemCount do
begin
edtItemPrice := TEdit.create(self);
edtItemPrice.parent := pnlItemPrice;
edtItemPrice.Align:=altop;
edtItemPrice.top:= pnlItemPrice.height;
edtItemPrice.Height:=10;
edtItemPrice.text := 'Item '+ IntToStr(k)+ ' ' + 'Price' ;
edtItemPrice.font.color := clred;
end;
end;

The SECOND hurdle is the DB post as below

procedure TfrmSalesAgentTasks.AddClick(Sender: TObject);
var n: integer;
begin
for n := 0 to lstProdOD.Items.count do
ADOTable2.Append;
ADOTable2.Active:=true;
ADOTable2.Append;
ADOTable2['OrderID']:=cbxOrderID.Text;
ADOTable2['ProductID']:=lstProdOD.selected[n];
ADOTable2['UnitPrice']:=lstUnitPriceOD.selected[n];
ADOTable2['Quantity']:=edtItemPrice.SelText;
ADOTable2['Discount']:=edtUnitPrice.SelText;
ADOTable2.Post;
application.MessageBox('Database record inserted successfully','Information',MB_OK or MB_IconInformation)
end;

ERROR: raised exception class ElistError with message 'List index out of bounds (13)'. Process stopped. Use Step or Run to continue.
Reply With Quote
  #2  
Old 06-11-2018, 07:13 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 180
Default

I believe the first issue can be fixed by changing
Code:
ItmIndx := lstProdOD.items[lstProdOD.ItemIndex]; //you are always selecting the SAME item, ItemIndex returns the index of the selected row
to
Code:
ItmIndx := lstProdOD.items[I];
and the list issue, "list index out of bounds" is due to your for loop's upper limit

Code:
for n := 0 to lstProdOD.Items.count do
should be
Code:
for n := 0 to lstProdOD.Items.count - 1 do
Reply With Quote
  #3  
Old 06-12-2018, 04:08 AM
durbslaw durbslaw is offline
Junior Member
 
Join Date: Jun 2018
Posts: 2
Default

Thanks Rojam
Reply With Quote
Reply

Tags
listbox index tedit text

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:03 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.