Solved

Multiple listview selection + multiple sockets connections error message

Posted on 2007-11-24
7
477 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…

830 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