Home > Back-end >  ListView to add Item, always an error: list index out of bounds (2)
ListView to add Item, always an error: list index out of bounds (2)

Time:10-24

In a ListView build several Column
 
Item:=lstTest. Items. The add;
Item. Caption:=str1;
Item. Subitems. Add (str2);
Item. Subitems. Add (str3);



Perform to the item. The caption:=str1; Times: wrong list index out of bounds (2)
I built five Column without overflow!
Please people

CodePudding user response:

I tested, no problem,,

CodePudding user response:

reference 1st floor HSFZXJY response:
I tested, no problem,,


I always use well, all of a sudden.
I looked at it and I'm a total of five Column, add the time actually starts from the fourth Column to write, so will be out of bounds (2)

But why the item. The caption will start from fourth, how all did not find the reason

CodePudding user response:

Stick a picture,,

CodePudding user response:

reference HSFZXJY reply: 3/f
post a picture,,


? (that is, can't map to the fault, error at the same time can see write first caption values to the fourth Column

CodePudding user response:

You should carefully check code is other place call causes errors,,

CodePudding user response:

No code, no truth

CodePudding user response:

Looked at it carefully, I wrote this code is in the IdServer. Excute, when testing the client just send a message is an error, so you should not synchronization problem, and I later added M_Lock. Enter and M_Lock ListView Leave protection, at the same fault again

CodePudding user response:

TThread. The synchronize synchronization function

CodePudding user response:

refer to the eighth floor HSFZXJY response:
TThread. The synchronize synchronization function


Where is it written? Should not synchronization problem, I have tracking, is performed only once, there exists no problem of resource sharing

CodePudding user response:

That's all right, and your post code will die!

CodePudding user response:

I also want to ah, really can't stick, you know, I will rewrite a at home

CodePudding user response:

11 references Jikycc response:
I also want to ah, really can't stick, you know, another day I at home to rewrite a

I don't understand,, what's the matter?

CodePudding user response:

Depend, code before and after just a few lines, have not posted??
Do you like this it is better to ask questions,
Do not appear on the seventh floor IdServer,,, who knows how do you add how to remove?
Listview you don't have to thread operation is inherently wrong,

CodePudding user response:

Business secret? No,,

CodePudding user response:

Watching this few lines of code no problem, you don't stick the context code, who know where the problem?

CodePudding user response:

 
Procedure TServer. IdServerExecute (AThread: TIdPeerThread);
Var
MSG: String;
The begin
MSG:=AThread. Connection. ReadLn;
If MSG="' then the exit;

ReadMsg (MSG);
end;

Procedure TServer. ReadMsg (MSG: String);
Var
Item: TListItem;
The begin
M_Lock. Enter;//M_Lock is a global variable TCriticalSection
Item:=ListView1. Items. The Add;
Item. Caption:='0';//step error here
Item. SubItems. Add (' 1 ');
Item. SubItems. Add (' 2 ');
Item. SubItems. Add (' 3 ');
Item. SubItems. Add (MSG);
M_Lock. Leave;
end;


A process is the same error again

CodePudding user response:

Write wrong, is to restart a thread to execute ReadMsg, will also be an error?

CodePudding user response:

refer to the eighth floor HSFZXJY response:
TThread. The synchronize synchronization function


Use the Synchronize to solve problems, the original VCL can display controls can only use the main thread to control, I in the Execute another initialize a thread class used to process the message, and then add the ListView functions in the process of the Synchronize, problem solved,

CodePudding user response:

Congratulations to wow,,,,
  • Related