Link to home
Start Free TrialLog in
Avatar of valvet
valvet

asked on

Parsing socket data

Hi,

I'd like to say that my delphi skills isen't go good.

First I've opened a connection to a server and executing a command called topposter <username> <password>
This used to be come out in a weird format with crlf codes all over the place, but I found out that if I used this:

var
  d: string;
begin
  d := Socket.ReceiveText;
  d := AdjustLineBreaks(d); // this I dident know
  ...

It gets in the correct order in the memo pad, without the char(10) and char(13). Now that that's fixed, the output looks like this:

4139
1 AnsiC 151
2 Carta 91
3 awash 69
4 r00tb0y 62
5 zube 55
6 Merc_II 34
7 zzgner 30
8 easteregg 29
9 DSF2 24
10 skaarj56 16
10 ReKsOz 16
11 ^sascha^ 15
11 Hoookie 15
12 bob96 12
13 Paolo2 11
13 Skox 11
13 vanbolle 11
13 vincentde 11
14 Sna-Q 10
14 AgentX 10
15 blahblah1 9
15 Boardie 9
16 VitrioliQ 8
16 TuMoR 8
17 wizardofn 7
17 rizwanir1 7
17 AmirKhan 7
17 Storemate 7
17 JoeyBalbo 7
18 grove 6
18 PL_BOY 6
18 NighTrain 6
18 Banin 6
18 J0eLeB0ss 6
18 JohnnyWay 6
18 got 6
19 Kohan 5
19 FLAT|away 5
19 MicroCrac 5
19 funnyusa 5
19 rvan836 5
19 dzanus 5
19 paule111 5
19 ItSiK 5
19 groham 5
19 assman17 5
19 Speed11 5
19 Starsplas 5
19 edy2k2 5
19 leeuwtje2 5
19 gloubibou 5
20 znice 4
20 Hugo_Boss 4
20 infusion 4
20 GSG9 4
20 Blackhol^ 4
20 stealth 4
20 megapsy 4
20 Blueye 4
20 McViper 4
:::BREAK:::

How do I get that into a listview in the correct order?
That would be: rank / nickname / sites

My listview has 3 colums..

But I think we need to put all that infomation above into a var, because its not the only output I get, since when I connect I get "go" if I can connect and "stop" if I can't, and then a greeting message. I don't want that into the listview aswell.

We need to make a function that would split all this, cause theres more commands with the same output as this, so a function I could use again would be great.

The output when I connect looks like this:

go

Welcome back!  You are recognized as an OP.

This shouldn't get into the topposter listview.. hope someone can help, thanks.

- Michael
Avatar of rbohac
rbohac

You can do the following to onlu process the lines that start with a rank

var sRank:String;
iRank:Integer;

{insert your loop here, while or for}
try
  sRank := copy(sDataString,1,pos(' ',DataString)-1);
  iRank := StrToInt(sRank);
  except
  continue; {will continue to next iteration of the loop if the first value is not a number}
  end;

{process the rest of the data}

{end loop here}


Something else you might consider is using a component called TSortGrid. You can put each value in a colum, and sort on the fly in thr grid instead of creating your own custom sort methods.

You can find that component here: http://www.torry.net/stringgrids.htm
Avatar of valvet

ASKER

Hi,

its not the word rank, its just numbers / nickname / numbers.. and that made no sence at all, my delphi skills isen't very good :(
exactly. StrToInt tries to convert a string to an integer. if the string you are trying to convert is not an integer it will throw an exception.

'1234'    = 1234
'Welcome' = exception

so in a loop if you try to convert a string to an integer, and handle the exception if the string is not an exception, the the resulting data will only be the lines that start with a valid rank
Avatar of valvet

ASKER

err this is getting a little to technical for me, I have no idea what you're talking about.
try this for a test...

put two memo's on your form.

populate memo 1 with your data

add a button and put the following in it...


procedure TForm1.Button1Click(Sender: TObject);
var sRank:String;
iRank:Integer;
x:Integer;
begin
Memo2.Lines.Clear;
for x:= 0 to Memo1.Lines.Count -1 do
  begin
    try
     sRank := copy(Memo1.Lines[x]),1,pos(' ',Memo1.Lines[x])-1);
     iRank := StrToInt(sRank);
     except
     continue;
    end;
  Memo2.Lines.Add(Memo1.Lines[x]);
  end;

end;
Avatar of valvet

ASKER

All I want is a function that can parse the data above and throw it into a listview in the correct order:
rank - nickname - sites
Avatar of valvet

ASKER

k let me try, diden't see your post
Avatar of valvet

ASKER

[Error] Unit1.pas(104): Not enough actual parameters
[Error] Unit1.pas(112): '.' expected but ';' found

Would it be possible to make a function for the parsing of all this data, cause I have other commands that spit out data in the same order
Just to correct our friend's code:

procedure TForm1.Button1Click(Sender: TObject);
var
  sRank:String;
  iRank: Integer;
  x: Integer;
begin
  Memo2.Lines.Clear;
  for x := 0 to Memo1.Lines.Count -1 do
  begin
    try
      sRank := copy(Memo1.Lines[x],1,pos(' ',Memo1.Lines[x])-1);
      iRank := StrToInt(sRank);
    except
      continue;
    end;
  Memo2.Lines.Add(Memo1.Lines[x]);
end;
Avatar of valvet

ASKER

Yes, but hes using memo pad's, thats not what I need.

I need a function to parse the data above and put it into a listview in the correct order: rank - nickname - sites
Where was the difference in code?

I only used memo's because I was trying to show you how to parse out the lines that started with a number
>[Error] Unit1.pas(104): Not enough actual parameters
>[Error] Unit1.pas(112): '.' expected but ';' found

>sRank := copy(Memo1.Lines[x],1,pos(' ',Memo1.Lines[x])-1);
>end;
here is a quick and dirty way of doing it.

The sort algorithm probably can be written faster, but it works, and your dataset isn't that big.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
type
  pUserItem = ^TUserItem;
  TUserItem = record
  rank:Integer;
  username:String;
  sites:Integer;
  end;
var sRank,sTemp,sUsername:String;
iRank,iSites:Integer;
x:Integer;
items:Array of PUserItem;
pTemp:Pointer;
Swapped,Ordered:Boolean;
begin
setlength(Items,0);
for x:= 0 to Memo1.Lines.Count -1 do
 begin
   try
    sRank := copy(Memo1.Lines[x],1,pos(' ',Memo1.Lines[x])-1);
    iRank := StrToInt(sRank);
    sTemp := copy(Memo1.Lines[x],pos(' ',Memo1.Lines[x])+1,999);
    sUsername := copy(sTemp,1,pos(' ',sTemp)-1);
    iSites :=  StrToInt(copy(sTemp,pos(' ',sTemp)+1,999));
    except
    continue;
   end;
 SetLength(items,Length(Items)+1);
 New(Items[High(Items)]);
 Items[High(Items)]^.rank := iRank;
 Items[High(Items)]^.username := sUsername;
 Items[High(Items)]^.sites := iSites;
 end;


{Order By Rank}
Swapped:=False;
Ordered := False;
While not Ordered do
  begin
  Swapped:=False;
  for x:=0 to High(Items)-1 do
    begin
    if (Items[x]^.rank < Items[x+1]^.rank) then
      begin
      {swap}
      pTemp := Items[x];
      Items[x] := Items[x+1];
      Items[x+1]:=pTemp;
      Swapped := True;
      end;
    end;
  if not Swapped then ordered := True;
  end;


{Now order by username}
Swapped:=False;
Ordered := False;
While not Ordered do
  begin
  Swapped:=False;
  for x:=0 to High(Items)-1 do
    begin
    if (Items[x]^.rank = Items[x+1]^.rank) then
      if(Items[x]^.username > Items[x+1]^.username) then
        begin
        { swap}
        pTemp := Items[x];
        Items[x] := Items[x+1];
        Items[x+1]:=pTemp;
        Swapped := True;
      end;
    end;
  if not Swapped then ordered := True;
  end;

{Now order by sites}
Swapped:=False;
Ordered := False;
While not Ordered do
  begin
  Swapped:=False;
  for x:=0 to High(Items)-1 do
    begin
    if (Items[x]^.rank = Items[x+1]^.rank) then
      if(Items[x]^.username = Items[x+1]^.username) then
        if (Items[x]^.sites < Items[x+1]^.sites) then
        begin
        { swap}
        pTemp := Items[x];
        Items[x] := Items[x+1];
        Items[x+1]:=pTemp;
        Swapped := True;
      end;
    end;
  if not Swapped then ordered := True;
  end;
Memo2.Lines.Clear;
for x:=0 to High(Items) do
  Memo2.Lines.Add(IntToStr(Items[x]^.rank)+':'+Items[x]^.username+':'+IntToStr(Items[x]^.sites))

end;

end.
>[Error] Unit1.pas(104): Not enough actual parameters
>[Error] Unit1.pas(112): '.' expected but ';' found

>sRank := copy(Memo1.Lines[x],1,pos(' ',Memo1.Lines[x])-1);
>end;
what version of delphi are you using? I was able to compile and run this just fine.
my 2 cents

drop a TListView in the form and let these functions do their job.

procedure SetList(list: TListView); // To prepare the list
begin
  list.Columns.Add;
  list.Columns.Add;
  list.Columns.Add;
  list.Column[0].Caption := 'Rank';
  list.Column[1].Caption := 'Nick';
  list.Column[2].Caption := 'Sites';
  list.ViewStyle := vsReport;
  list.SortType := stText;
end;

procedure ParseList(str: string; list: TListView);
var
  i, j: integer;
  item: TListItem;
begin
  for i := 0 to 3 do
    if str[i] = ' ' Then
      for j := i + 1 to length(str) do
        if str[j] = ' ' then
        begin
          item := list.Items.Add;
          item.Caption := Copy(str,0,i);
          item.SubItems.Add(Copy(str,i + 1,j - i - 1));
          item.SubItems.Add(Copy(str,j,length(str)));
        end;
end;


then just set the list calling SetList and pass the string to the function along with the name of the TListView component like this:

SetList(ListView1);
ParseList('12 stealth 4', ListView1);

it will auto-sort based on the Caption property of the Items (the Rank number in this case)
Delphi 4 and 5
In the actual code we got an extra '(' in the copy function

sRank := copy(Memo1.Lines[x]),1,pos(' ',Memo1.Lines[x])-1);
Avatar of valvet

ASKER

Sorry been away lately.

Okay this is almost working (I think) heres my full code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ScktComp, ComCtrls, DdeMan;

type
  TForm1 = class(TForm)
    wtSocket: TClientSocket;
    ListTop: TButton;
    Connect: TButton;
    Disconnect: TButton;
    ListView1: TListView;
    StatusBar1: TStatusBar;
    Memo1: TMemo;
    procedure DisconnectClick(Sender: TObject);
    procedure ConnectClick(Sender: TObject);
    procedure wtSocketRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure ListTopClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure SetList(list: TListView); // To prepare the list
begin
 list.Columns.Add;
 list.Columns.Add;
 list.Columns.Add;
 list.Column[0].Caption := 'Rank';
 list.Column[1].Caption := 'Nick';
 list.Column[2].Caption := 'Sites';
 list.ViewStyle := vsReport;
 list.SortType := stText;
end;


procedure ParseList(str: string; list: TListView);
var
 i, j: integer;
 item: TListItem;
begin
 for i := 0 to 3 do
   if str[i] = ' ' Then
     for j := i + 1 to length(str) do
       if str[j] = ' ' then
       begin
         item := list.Items.Add;
         item.Caption := Copy(str,0,i);
         item.SubItems.Add(Copy(str,i + 1,j - i - 1));
         item.SubItems.Add(Copy(str,j,length(str)));
       end;
end;

procedure TForm1.DisconnectClick(Sender: TObject);
begin
  // close the socket
  wtSocket.Active := False;
end;

procedure TForm1.ConnectClick(Sender: TObject);
begin
  // server address
  wtSocket.Host := 'xx.xx.xx.xxx';
  // server port
  wtSocket.Port := 11223;
  // set active
  wtSocket.Active := True;
end;

procedure TForm1.wtSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  d: string;
begin
  if wtSocket.Active then
    begin
      d := Socket.ReceiveText;
      d := AdjustLineBreaks(d); // removes all crlf codes

      if Pos('go', d) > 0 then // got go
        begin
          StatusBar1.SimpleText := 'Connection granted';
        end;
      Memo1.Lines.Add(d);
      SetList(ListView1);
      ParseList(AdjustLineBreaks(d), ListView1);

  end;
end;

procedure TForm1.ListTopClick(Sender: TObject);
var
 crlf: string;
begin
  crlf := char(13) + char(10);
  if wtSocket.Active then
    wtSocket.Socket.SendText('topposter user pass' + crlf);
end;

end.


It looks like this: http://www.yay13.subnet.dk/parse.jpg which doesn't make mutch sence..

- Michael
Avatar of valvet

ASKER

err damn subnet, copy/paste into ie and it should work, might not if you just click it.
it's forbidden.. have an ip restriction?
i see what you did w/ the tlistview, but that is an ascii based sort, so therefor your numerical values will not display in the correct order
Avatar of valvet

ASKER

Yes it have IP restriction, so I can't let you guys test it out sadly. And yes its ascii something char(10) char(13) inbetween the data, not sure how to get it right. Even tho I used: d := AdjustLineBreaks(d); // removes all crlf codes

- michael
no, i was saying that by using the tlistview, it will sort based on the ascii code of the numbers, not the nmbers itself..

example:

1
11
12
13
14
...
18
19
2
20
21
22


instead of
1
2
3
4
5
...
7
8
9
10
11
12
etc...
Avatar of valvet

ASKER

oh okay, well how can we fix that then? It should be possible I hope..
the bubble sort code in the code I showed you doesn't have that problem (the full unit I posted yesterday)
Avatar of valvet

ASKER

I am using that code, it still gets parsed wrong.
Whats wrong with it?
still forbidden
Forbidden
You don't have permission to access /parse2.jpg on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/1.3.27 Server at www.yay13.subnet.dk Port 80
Avatar of valvet

ASKER

well.. it workes here, try copy/paste into IE, don't click the link from inhere.. subnet is just being crappy as always
what are the permissions on parse2.jpg?

type this: "chmod o+rx parse2.jpg"
Avatar of valvet

ASKER

nah its a windows server, I don't need to set permissions.

let me upload it under another name:

http://www.yay13.subnet.dk/parse.jpg
www.yay13.subnet.dk/parse.jpg

copy/paste into IE
yet again... Running apache on windows, eh?

Forbidden
You don't have permission to access /parse.jpg on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/1.3.27 Server at www.yay13.subnet.dk Port 80
Avatar of valvet

ASKER

Its not my server.. subnet.dk is a free hosting service.

okay last try, if this doesn't work then whatever.

http://www.yay13.subnet.dk/grr.html
I see it.

Use this as your parselist procedure instead

procedure ParseList(str: string; var list: TListView);
var sRank,sTemp,sUsername,sSites:String;
begin

   sRank := copy(str,1,pos(' ',str)-1);
   sTemp := copy(str,pos(' ',str)+1,999);
   sUsername := copy(sTemp,1,pos(' ',sTemp)-1);
   sSites :=  copy(sTemp,pos(' ',sTemp)+1,999);
end;
Avatar of valvet

ASKER

ok nothing's happening:

procedure ParseList(str: string; var list: TListView);
var sRank,sTemp,sUsername,sSites:String;
begin

  sRank := copy(str,1,pos(' ',str)-1);
  sTemp := copy(str,pos(' ',str)+1,999);
  sUsername := copy(sTemp,1,pos(' ',sTemp)-1);
  sSites :=  copy(sTemp,pos(' ',sTemp)+1,999);
end;

procedure TForm1.wtSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  d: string;
begin
  if wtSocket.Active then
    begin
      d := Socket.ReceiveText;
      d := AdjustLineBreaks(d); // removes all crlf codes

      if Pos('go', d) > 0 then // got go
        begin
          StatusBar1.SimpleText := 'Connection granted';
        end;
      Memo1.Lines.Add(d);
      SetList(ListView1);
      ParseList(AdjustLineBreaks(d), ListView1);

  end;
end;

I just get blank fields
my fault.. i'm at work and the boss walked in..

procedure ParseList(str: string; var list: TListView);
var sRank,sTemp,sUsername,sSites:String;
item: TListItem;
begin

  sRank := copy(str,1,pos(' ',str)-1);
  sTemp := copy(str,pos(' ',str)+1,999);
  sUsername := copy(sTemp,1,pos(' ',sTemp)-1);
  sSites :=  copy(sTemp,pos(' ',sTemp)+1,999);
  item := list.Items.Add;
  item.Caption := sRank;
  item.SubItems.Add(sUsername);
  item.SubItems.Add(sSites);
end;


Avatar of valvet

ASKER

Okay hmm, check this site again: www.yay13.subnet.dk/grr.html refresh it.

when I use d := AdjustLineBreaks(d); // removes all crlf codes

I still get the same result even tho the output is different
without having access to the data stream, I cant test this but try...


procedure ParseList(str: string; var list: TListView);
var sRank,sTemp,sUsername,sSites:String;
item: TListItem;
iRank:Integer;
begin
str := trim(str);
 sRank := Trim(copy(str,1,pos(' ',str)-1));
try
  iRank := StrToInt(sRank);
  except
  exit;
  end;
 sTemp := trim(copy(str,pos(' ',str)+1,999));
 sUsername := Trim(copy(sTemp,1,pos(' ',sTemp)-1));
 sSites :=  trim(copy(sTemp,pos(' ',sTemp)+1,999));
 item := list.Items.Add;
 item.Caption := sRank;
 item.SubItems.Add(sUsername);
 item.SubItems.Add(sSites);
end;
Avatar of valvet

ASKER

Hmm that seems to have the problem as the last code, no lines gets added. Thats add since you added:

sTemp := trim(copy(str,pos(' ',str)+1,999));
sUsername := Trim(copy(sTemp,1,pos(' ',sTemp)-1));
sSites :=  trim(copy(sTemp,pos(' ',sTemp)+1,999));
item := list.Items.Add;
item.Caption := sRank;
item.SubItems.Add(sUsername);
item.SubItems.Add(sSites);

again
Avatar of valvet

ASKER

oh and
[Hint] Unit1.pas(54): Value assigned to 'iRank' never used
Avatar of valvet

ASKER

I hope this isen't to mutch bother for you..

I kinda thought it was easy to parse, but since you don't have access to the stream then I can see why it can
Theres something different about the data stream. Your are not receiving one line at a time then when you call receivetext. The way you have the wtSocketReceive coded depends on that
Avatar of valvet

ASKER

Yes you might be right, heres the complete output:

www.yay13.subnet.dk/big.html


made a huge memopad and not using any parsing of any kind only:

procedure TForm1.wtSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  d: string;
begin
  if wtSocket.Active then
    begin
      d := Socket.ReceiveText;
//      d := AdjustLineBreaks(d); // removes all crlf codes

      if Pos('go', d) > 0 then // got go
        begin
          StatusBar1.SimpleText := 'Connection granted';
        end;
      Memo1.Lines.Add(d);
//      SetList(ListView1);
//      ParseList(d, ListView1);

  end;
end;
Avatar of valvet

ASKER

I put another pic on www.yay13.subnet.dk/big.html of the data from Socket Workbench. if you would like be to connect with any other program that might show a little more information about the data, just tell me the name.
try this and see what happens

procedure TForm1.wtSocketRead(Sender: TObject;
 Socket: TCustomWinSocket);
var
 d: string;
 stemp:String;
begin
 if wtSocket.Active then
   begin
   d := Socket.ReceiveText;
   if Pos('go', d) > 0 then // got go
     begin
     SetList(ListView1);
     while (pos(#13,d)) > 0 do
          begin
          sTemp := trim(copy(d,1,pos(#13,d)-1));
          ParseList(sTemp, ListView1);
          d := copy(d,1,pos(#13,d)+1);
          end;
     end;
   end;
 end;
Avatar of valvet

ASKER

Ok if I used #13 (enter) nothing happends, if I use #10 which I think is the control code not #13, the program crashes heh
did you replace #13 with #10 in all 3 places?

i can't do anymore unless I have access to the datastream.. sorry
Avatar of valvet

ASKER

Yes I replaced all 3 with 10.

Well I can give you the ip/port, but the only thing you will get is stop<control code> since its IP controlled. But maybe that gives an idea of the stream or do you need more data than that?
change the line that reads d := Socket.ReceiveText; to
d := Socket.ReceiveText+' '; and try again with the #10's
actually try...


procedure TForm1.wtSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
d: string;
stemp:String;
begin
if wtSocket.Active then
  begin
  d := Socket.ReceiveText+' ';
  if Pos('go', d) > 0 then // got go
    begin
    SetList(ListView1);
    while (pos(#10,d)) > 0 do
         begin
         sTemp := trim(copy(d,1,pos(#10,d)-1));
         ParseList(sTemp, ListView1);
         d := copy(d,1,pos(#10,d)+1);
         end;
    end
    else

  end;
 
end;
stupid form...
I wasn't finished...


procedure TForm1.wtSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
d: string;
stemp:String;
begin
if wtSocket.Active then
 begin
 d := Socket.ReceiveText+' ';
 if Pos('go', d) > 0 then // got go
   begin
   SetList(ListView1);
   while (pos(#10,d)) > 0 do
        begin
        sTemp := trim(copy(d,1,pos(#10,d)-1));
        ParseList(sTemp, ListView1);
        d := copy(d,1,pos(#10,d)+1);
        end;
   end
   else
   showmessage('no go');

 end;
 
end;
Avatar of valvet

ASKER

Crashes the program:

procedure TForm1.wtSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
d: string;
stemp:String;
begin
if wtSocket.Active then
begin
d := Socket.ReceiveText+' ';
if Pos('go', d) > 0 then // got go
  begin
  StatusBar1.SimpleText := 'go..';
  SetList(ListView1);
  while (pos(#10,d)) > 0 do
       begin
       sTemp := trim(copy(d,1,pos(#10,d)-1));
       ParseList(sTemp, ListView1);
       d := copy(d,1,pos(#10,d)+1);
       end;
  end
  else
  showmessage('no go');

end;

end;
Avatar of valvet

ASKER

Try connecting yourself:

procedure TForm1.ConnectClick(Sender: TObject);
begin
  // server address
  wtSocket.Host := '24.68.15.217';
  // server port
  wtSocket.Port := 11223;
  // set active
  wtSocket.Active := True;
end;

You'll get stop#10
i did.. i'll look at it here in a bit. I have to get some work done at work
Avatar of valvet

ASKER

Alright, thanks
Avatar of valvet

ASKER

Eek been trying all night, still can't get this working
does it disconnect you automatically when it is done sending data?
Avatar of valvet

ASKER

Nope, it stays alive until you disconnect the socket. Theres no idle time limit
Avatar of valvet

ASKER

You only get disconnectet because you don't have access, you'll receive stop#10#13 (I think) and then it disconnects you
Avatar of valvet

ASKER

Hmm seems that EE has been up and down recently, hope you're still with me.

- Michael
Avatar of valvet

ASKER

Okay I was in a help channel shortly and was told this:

"maybe create a versatile parser that takes an array of place holders and the string to parse and does it, that way it's dynamic.
parse_serverstring(thestringfromserver, rank, user, sites)
where the number of arguments are dynamic
maybe even an array of args, like array[rank, user, sites]
then you just fill  them from the string"

And then he quit.. does that make any sense to you?
procedure TForm1.Button1Click(Sender: TObject);
var
i,x : Integer;
s : string;
begin
  s := Socket.ReceiveText;
  s := AdjustLineBreaks(s); // this I dident know
  with ListView1.Items.Add do
  begin
    s := Memo1.Lines[i];
    Caption := Copy(s,1,Pos(#32,s));
    system.Delete(s,1,Pos(#32,s));
    SubItems.Add(Copy(s,0,Pos(#32,s)));
    system.Delete(s,1,LastDelimiter(#32,s));
    SubItems.Add(s);
  end;
end;
oops
my mistake


try this instead

procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
begin
  s := Socket.ReceiveText;
  s := AdjustLineBreaks(s); // this I dident know
  with ListView1.Items.Add do
  begin
    Caption := Copy(s,1,Pos(#32,s));
    system.Delete(s,1,Pos(#32,s));
    SubItems.Add(Copy(s,0,Pos(#32,s)));
    system.Delete(s,1,LastDelimiter(#32,s));
    SubItems.Add(s);
  end;
end;
ok ok... this one

procedure TForm1.WSocket1DataAvailable(Sender: TObject; Error: Word);
var
s : string;
begin
  s := TWSocket(Sender).Receivestr;
  s := AdjustLineBreaks(s); // this I dident know
  with ListView1.Items.Add do
  begin
    Caption := Copy(s,1,Pos(#32,s));
    system.Delete(s,1,Pos(#32,s));
    SubItems.Add(Copy(s,0,Pos(#32,s)));
    system.Delete(s,1,LastDelimiter(#32,s));
    SubItems.Add(s);
  end;
end;
ASKER CERTIFIED SOLUTION
Avatar of joepezt
joepezt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial