Solved

Multiple listview selection + multiple sockets connections error message

Posted on 2007-11-24
7
475 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 28

Accepted Solution

by:
2266180 earned 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 64
Working this component WebCopy with proxy, help 3 84
find a node in VST 2 68
scroll down TListBox component in Delphi 1 11
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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