Search code examples
freepascal

how do I use setstate (lnet)?


When I use setstate I always get this error: unit1.pas(34,49) Error: Only class methods, class properties and class variables can be referred with class references, why does this error occur? I think the error lays in ssNoDelay, as without it the before mentioned error doesn't happen.

I made this empty project as an example:


{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, lNetComponents, lNet;

type

  { TForm1 }

  TForm1 = class(TForm)
    LTCPComponent1: TLTCPComponent;
    procedure FormCreate(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  LTCPComponent1.SocketClass.SetState(ssNoDelay);
end;

end.

Solution

  • SetState has to be used on a TLSocket, not on the TLCTPComponent. This means you can only use SetState when you already have a connection you want to apply one of the options (ssNoDelay for example) on (so the best solution is to use setstate in the OnAccept / OnConnect procedure if you want to use an option from the start).