Home > Back-end >  Delphi 7 index crossed the list index out of bounds (1) ask ace to help solve, make for a few days!!
Delphi 7 index crossed the list index out of bounds (1) ask ace to help solve, make for a few days!!

Time:09-26


Made a linkage is always at the county level 3 parts of the city will always be the occasional a record index of crossing the line, some normal, solve high...

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the problem part --
While not Eof do

The begin

Pxianname. ItemIndex:=0;
Pxianname. Items. The Add (FieldByName (' xianname). AsString) are identical.
StringList3. Add (FieldByName (' id '.) AsString) are identical.
Next;

The end;
//pxianid. Text:=StringList3. Strings [pxianname. ItemIndex];

End

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --




Procedure TForm1. FormShow (Sender: TObject);


The begin


StringList1:=TStringList. Create;//create constant class
StringList2:=TStringList. Create;//create constant class
StringList3:=TStringList. Create;//create constant class





With ADOQuery1 do

The begin

//query table
SQL. The Clear;
SQL. The add (' select id, shengname from sheng order by id asc ');
The open;


While not Eof do
The begin

Pshengname. Text:='please select a county;
Pshengname. Items. The Add (FieldByName (' shengname). AsString) are identical.
StringList1. Add (FieldByName (' id '.) AsString) are identical.
Next;
The end;


The end;

The end;







Procedure TForm1. PshengnameChange (Sender: TObject);



The begin//events



Pshengid. Text:=StringList1. Strings [pshengname. ItemIndex];



Pshiname. Items. The Clear;
Pshiname. ItemIndex:=0;

Pxianname. Items. The Clear;
Pxianname. ItemIndex:=0;


//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- city processing -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --



With ADOQuery2 do//market-making table record cycle show

The begin//city

SQL. The Clear;
SQL. The Add (' Select id, shiname from shi where shengid='+ StringList1. Strings [pshengname. ItemIndex] +' order by id desc ');
The Open;





If RecordCount=0 then {-- -- -- -- -- - the city of 0, dealing with the municipal and county part -- -- -- -- -- -- -- --}


The begin

Pshiname. Items. The Clear;
Pshiname. Text:='please add city;
Pshiid. Text:='0';

Pxianname. Items. The Clear;
Pxianname. Text:='please add county;
Pxianid. Text:='0';

End




The else {-- -- -- -- -- - the city is not 0, parts processing, -- -- -- -- -- -- -- --}


Begin//the city is not 0





While not Eof do {-- -- -- -- -- - processing, part of -- -- -- -- -- -- -- --}

The begin

Pshiname. ItemIndex:=0;
Pshiname. Items. The Add (FieldByName (' shiname). AsString) are identical.
StringList2. Add (FieldByName (' id '.) AsString) are identical.
Next;
The end;
Pshiid. Text:=StringList2. Strings [pshiname. ItemIndex];





With ADOQuery3 do {-- -- -- -- -- - deal with county part -- -- -- -- -- -- -- --}

The begin//county
SQL. The Clear;
SQL. The Add (' Select id, xianname from xian where shengid='+ StringList1. Strings [pshengname. ItemIndex] +' and shiid='+ StringList2. Strings [pshiname. ItemIndex] +' order by id desc ');
The Open;



If RecordCount=0 then {-- -- -- -- -- - county is 0, processing county part -- -- -- -- -- -- -- --}

The begin

Pxianname. ItemIndex:=0;
Pxianname. Text:='please add county;
Pxianid. Text:='0';

End


Else {-- -- -- -- -- - county is not 0, processing county part -- -- -- -- -- -- -- --}


The begin




While not Eof do

The begin

Pxianname. ItemIndex:=0;
Pxianname. Items. The Add (FieldByName (' xianname). AsString) are identical.
StringList3. Add (FieldByName (' id '.) AsString) are identical.
Next;

The end;
//pxianid. Text:=StringList3. Strings [pxianname. ItemIndex];

End

The end;//county



The end;//the city is not 0





The end;//the city



The end;//event

CodePudding user response:

Didn't watch carefully, but should be
Pxianname. Items. The Add (FieldByName (' xianname). AsString) are identical. This error

Look at the record of this field in a database, there should be a null or empty values

Stringlist, if you add a null value will not increase the count, so they have cross-border issues
  • Related