【发布时间】:2015-03-11 18:58:05
【问题描述】:
我收到此错误消息:
列表索引越界 (1)
尝试从我的数据库中选择信息时。我正在使用 Delphi XE7、MySQL 6.2、FDConnection 和 FDQuery。我的代码是:
Procedure TAppointmentForm.GetTreatPrice;
Begin
TreatPriceQuery.SQL.Text:= 'Select Cost from Treatment where TreatName = '+quotedstr(Treatment)+'';
TreatPriceQuery.Open;
TreatPrice:= TreatPriceQuery.FieldByName('Cost').AsInteger;
End;
我正在使用 CheckBoxList 来获取 Treatment。我的代码是:
Procedure TAppointmentForm.GetAppCost;
Var
Count: Integer;
begin
for Count := 0 to (Count1-1) do
Begin
if TreatmentCheckListBox.State[Count] = cbChecked then
Begin
Treatment:= TreatmentCheckListBox.Items.Strings[Count];
GetTreatPrice;
AppCost:= AppCost + TreatPrice;
End
Else
AppCost:= AppCost;
End;
end;
【问题讨论】:
-
在
GetAppCost()的循环中,Count1来自哪里,分配给它的是什么?循环需要使用来自TreatmentCheckListBox.Items.Count的值,如果它还没有这样做的话。 -
另外,为什么要使用全局/成员变量来传递
Treament和TreatPrice值?为什么不直接给GetTreatPrice()一个输入参数和一个返回值呢? -
Count1是我用来将它们添加到列表中的变量 -
那么
Count1可能与实际的Items.Count不同步。您应该在循环中使用实际的Items.Count。AppCost:= AppCost也是多余的。
标签: mysql delphi delphi-xe7 firedac