TTreeView
填充的DB table
。然后,我根据已检查的query
项目,运行该代码&value
从该表中的另一个column
获取TTreeView
,并将其添加到TMemo
。procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
test: string;
begin
for i:=0 to TreeView1.Items.Count do
begin
if TreeView1.Items[i].Checked then
begin
test := TreeView1.Items.Item[i].Text;
try
Query1.SQL.Text := 'SELECT column2 FROM someTable WHERE column1='''+test+'''';
Query1.Open;
finally
Memo1.Lines.Add(Query1.FieldByName('column2').Value);
end;
Query1.Close;
end;
end;
for i:=0 to TreeView1.Items.Count do TreeView1.Items.Item[i].Checked := false;
end;
除此以外,一切正常,Access Violation error
一旦启动,我会得到。Delphi调试器将其标识为源于此代码行:
if TreeView1.Items[i].Checked then
并说:Expression illegal in evaluator
我不了解该行代码的问题所在。愿意分享您的想法吗?
count从1开始,而items从零开始索引。因此,当i]达到count时,您将获得AV,该AV比可以索引的索引多1。您需要更改此行for i := 0 to TreeView1.Items.Count do
to
for i := 0 to TreeView1.Items.Count - 1 do
您的代码中有2个地方需要应用此更改。