[Lazarus] Lazarus implementation of TListView etc?

José Mejuto joshyfun at gmail.com
Tue Nov 3 02:40:11 CET 2015


El 02/11/2015 a las 20:32, Bo Berglund escribió:

>> IMHO using lnet or Synapse would be a lot "clearer" than using the
>> overly complex Indy Library.
> I had already looked at Synapse, but it is blocking.
> I did not know about lnet (or INet as it is shown when one searches)
> before but now I have had a look and it seems to fit the bill for me
> since it is event oriented, like I need for this particular task.
>

Hello,

I was following your thread from the beginning and or I do not 
understand absolutely nothing about your needs or you are focusing the 
problem in the opposite way. Let me explain me, I think you had 
inherited a GUI app which you need to transform in a console one and 
this GUI app uses events to coordinate data flows, so in example the app 
connects to a server, gets a web page and some event handler process 
this data and outputs something to a file. The problem was that the 
event handler also updates information on screen (AKA TListView, ...) 
which you already removed.

That's fine, but my question is why you need event sockets ? I had 
converted some small apps with events in console ones and using only 
blocking sockets because I do not need to update screen information in 
GUI, only in console and as the console (in my case) do not need events 
from the user like response to keypress I do not need real events, so I 
wrote your "thread" in the main thread and manually "evented" each 
reception, something like this in pseudocode:

begin
   Socket.Connect...
   MyClass.Connect(Socket);
   Socket.http('xxxxx');
   while Socket.Connected do begin
     If Timedout() then break;
     ReceivedBytes:=Socket.Read(Buffer,0);
     if ReceivedBytes>=0 then begin
        ReceivedBytes:=Socket.Read(Buffer,ReceivedBytes);
        //Now I call the event reception
        //not a real event, but that's not important.
        MyClass.Received(Socket,Buffer,ReceivedBytes);
     end;
   end;
   Socket.Close;
   MyClass.Disconnect(Socket,REASON_GREACEFUL_CLOSE);
   Socket.Free;
end;

Of course the same can be done with multiple sockets at a time and call 
different handlers based in the socket that connects, receive data, etc...

Even if you use http transfers its more easy with blocking, something like:

Document:=http.get('http://xxxxxxx);
MyClass.Connect();
MyClass.Receive(Buffer,Length(Buffer));
MyClass.Closed();

Your class do not know if the data comes from an event or from a 
blocking socket. A different thing is if you need some kind of timing 
between operations.

-- 





More information about the Lazarus mailing list