Solved

Multiple listview selection + multiple sockets connections error message

Posted on 2007-11-24
7
463 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:ciuly
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:ciuly
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 28

Accepted Solution

by:
ciuly 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:ciuly
ID: 20345060
glad you made it :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

9 Experts available now in Live!

Get 1:1 Help Now