Solved

Multiple listview selection + multiple sockets connections error message

Posted on 2007-11-24
7
471 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now