?
Solved

Multiple listview selection + multiple sockets connections error message

Posted on 2007-11-24
7
Medium Priority
?
489 Views
Last Modified: 2010-04-05
Im trying this

[CODE]
procedure TForm1.SendData1Click(Sender: TObject);
var
  Socket: TCustomWinSocket;
  Data: string;
  i: integer;
begin
  if not assigned(listview1.Selected) then exit;
  for i := 0 to listview1.Items.Count do
  Socket := TCustomWinSocket(listview1.Items[i].Selected);
  Data := inputbox('Send Data','Caption','command');
  Socket.SendText(Data);
end;
[/CODE]

and im getting this error:

Project xxxx.exe raised exception class EAccessViolation with message 'Access violation at address 00437EC8 in module xxxx.exe. Read of address 00000004'. Process stopped.

The code is a multiselect listview that send a comment to multiple servers, it only worked to me without multiselect using" listview1.Selected.Data" in >>>  Socket := TCustomWinSocket(listview1.Items[i].Selected);

Also tried listview1.Items[i].Data and doesnt work.
0
Comment
Question by:epagos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 20343497
Socket := TCustomWinSocket(listview1.Items[i].Selected);
is incorrect. the items property of the listview returns a TListItem.

TCustomWinSocket(listview1.Items[i].Data)
will work IF you are setting it before use.

when you add the customwinsocket to the lsitview, you also need to set the data property of the listitem to the customwinsocket. somethinglike:

onconnect:

with listview1items.add do
begin
  caption:='whatever';
  data:=connectingclientobject which is derives from TCustomWinSocket;
end;
0
 
LVL 28

Expert Comment

by:2266180
ID: 20343509
also,

for i := 0 to listview1.Items.Count do

is wrong.

it should be

for i := 0 to listview1.Items.Count-1 do

more:

  for i := 0 to listview1.Items.Count do
  Socket := TCustomWinSocket(listview1.Items[i].Selected);

the above will assign to socket the values until the last one so it's aquivalent to
Socket := TCustomWinSocket(listview1.Items[listview1.Items.Count].Selected);

notice that I kept the

listview1.Items[i].Selected

even though it should be
listview1.Selected

your posted code is a mess alltogether :) I can't make out what you actually wanted to do, but hopefully with above mentioned problems fixed, you can post a cleaner code. if you still have problems.
0
 

Author Comment

by:epagos
ID: 20343608
could you give me a quick example besides all this socket stuff of how to put a multiple listview selection to a loop to do something (the same thing for all) with each selection ?
thnkx
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Accepted Solution

by:
2266180 earned 2000 total points
ID: 20343895
sure

var i:integer;
    l:tlistitem;
begin
  l:=listview1.Selected;
  for i:=1 to listview1.SelCount do
  begin
    showmessage(l.Caption);
    l:=listview1.GetNextItem(l, sdBelow, [isSelected]);
  end;
end;
0
 

Author Comment

by:epagos
ID: 20344133
Awesome thats a nice example, the l.caption was something i didnt understand without the example... now do you know how could i get the second column of the listview in l.caption? because the showmsg shows me the firs column only
0
 

Author Comment

by:epagos
ID: 20344417
i got it working, thank you very much ciuly, now i can get fun all night long :P
0
 
LVL 28

Expert Comment

by:2266180
ID: 20345060
glad you made it :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question