How may I use Socketclient (or another socket or TCP components like lNet) component with KOL?
How do I convert?
Mailing lists / lazarus / 2008-11
KOL socketclient object
12 messages · 7 people · –
- UUsuario Anónimo 3
- AAleš Katona 2
- KKutlay Ozger 2
- UUser 2
- BBogusław Brandys 1
- JJohn vd Waeter 1
- +1 more
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
From: Kutlay Ozger
How may I use Socketclient (or another socket or TCP components like lNet) component with KOL? How do I convert?
You can use 3rd party non visual (LCL is not used) components like lNet without any modifications. Just create needed objects in runtime and set all needed properties/events in runtime.
Yury Sidorov.
How may I use Socketclient (or another socket or TCP components like lNet) component with…
lNet non-visual can indeed be used anywhere BUT you need to understand the concept of .CallAction (see docs at http://members.chello.sk/ales/docs and homepage at http://lnet.wordpress.com) and that you'll need to integrate it into the main loop somehow (either directly, or if you're using some sort of widgetset then it might be possible to use that, but that's a bit more complicated).
If I put the unit lNetComponents in the uses onto KOL-CE application I get the run-time error: Project raised exception class 'External: SIGSEGV'.
Why?
This is my code:
{ KOL MCK } // Do not remove this line!
{$DEFINE KOL_MCK}
{$ifdef FPC} {$mode delphi} {$endif}
unit Unit2;
interface
uses Windows, Messages, KOL, lNetComponents {place your units here->}
{$IFDEF LAZIDE_MCK}, Forms, mirror, Classes, Controls, mckCtrls, mckObjs,
Graphics;
{$ELSE} ; {$ENDIF}
type
{ TForm2 }
{$I MCKfakeClasses.inc}
{$IFDEF KOLCLASSES} TForm2 = class; PForm2 = TForm2; {$ELSE OBJECTS}
PForm2 = ^TForm2; {$ENDIF CLASSES/OBJECTS}
TForm2 = {$IFDEF KOLCLASSES}class{$ELSE}object{$ENDIF}({$IFDEF
LAZIDE_MCK}TForm{$ELSE}TObj{$ENDIF})
Button1: TKOLButton;
Form: PControl;
KOLForm1: TKOLForm;
procedure Button1Click(Sender: PObj);
private
{ private declarations }
LTCPComponent1: TLTCPComponent;
public
{ public declarations }
end;
var
Form2 {$IFDEF KOL_MCK} : PForm2 {$ELSE} : TForm2 {$ENDIF} ;Thank you very much, best regards.
2008/11/11 Ale? Katona
Show quoted text 15 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081111/d6bfe43c/attachment-0001.html
You must create components dynamically.
It works like this.
procedure TForm1.FormCreate(Sender: TObject);
begin
LTCPComponent1:=TLTCPComponent.Create(nil);
end;Do not add component on form.
2008/11/11 Usuario An?nimo
Show quoted text 71 lines
I create the component dynamically (I do not drop the component onto the form) but if I put the unit "lNetComponents" in the uses I get the run-time error: Project raised exception class 'External: SIGSEGV'.
Why?
This is my code:
{ KOL MCK } // Do not remove this line!
{$DEFINE KOL_MCK}
{$ifdef FPC} {$mode delphi} {$endif}
unit Unit2;
interface
uses Windows, Messages, KOL, lNetComponents {place your units here->}
{$IFDEF LAZIDE_MCK}, Forms, mirror, Classes, Controls, mckCtrls, mckObjs,
Graphics;
{$ELSE} ; {$ENDIF}
type
{ TForm2 }
{$I MCKfakeClasses.inc}
{$IFDEF KOLCLASSES} TForm2 = class; PForm2 = TForm2; {$ELSE OBJECTS}
PForm2 = ^TForm2; {$ENDIF CLASSES/OBJECTS}
TForm2 = {$IFDEF KOLCLASSES}class{$ELSE}object{$ENDIF}({$IFDEF
LAZIDE_MCK}TForm{$ELSE}TObj{$ENDIF})
Button1: TKOLButton;
Form: PControl;
KOLForm1: TKOLForm;
procedure Button1Click(Sender: PObj);
private
{ private declarations }
LTCPComponent1: TLTCPComponent;
public
{ public declarations }
end;
var
Form2 {$IFDEF KOL_MCK} : PForm2 {$ELSE} : TForm2 {$ENDIF} ;2008/11/11 Kutlay Ozger
Show quoted text 96 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081111/0ea4f586/attachment-0001.html
@Kutlay Ozger. You can run a KOL-CE application with lNet?
2008/11/11 Usuario An?nimo
Show quoted text 146 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081111/bb3fb0f8/attachment.html
lNetComponents is the "visual" lNet package and it tries to make a LCLEventer which tries to integrate into LCL/widgetset main loop (see my callaction note from before).
Obviously this will fail without LCL, although I'd expect a compile-time error, not a runtime error.
If you get the time, can you give me a backtrace? lNetComponents uses the lclnet unit which depends on LCL units so it shouldn't have compiled.
Ale? Katona wrote 6 lines
Do not use the lNET visual components on a KOL project. Instead create them at runtime, like myTCP := tlTCP.Create(nil) See the "console" examples on how to use them.
The code inside the components does not get triggered by LCL-events. So you have to trigger the code yourself by frequently calling the CallAction method.
GL!
John
lNetComponents is the "visual" lNet package and it tries to make a LCLEventer which tries…
Ale? Katona pisze:
Show quoted text 6 lines
Try to use synapse library ported to KOL.
Boguslaw
I can?t assign the callbacks:
{ KOL MCK } // Do not remove this line!
{$DEFINE KOL_MCK}
{$ifdef FPC} {$mode delphi} {$endif}
unit ModuloDatos2;
interface
uses Windows, Messages, KOL {place your units here->}, lNet
{$IFDEF LAZIDE_MCK}, Forms, mirror, Classes, Controls, mckCtrls, mckObjs,
Graphics;
{$ELSE} ; {$ENDIF}
type
{ TForm3 }
{$I MCKfakeClasses.inc}
{$IFDEF KOLCLASSES} TForm3 = class; PForm3 = TForm3; {$ELSE OBJECTS}
PForm3 = ^TForm3; {$ENDIF CLASSES/OBJECTS}
TForm3 = {$IFDEF KOLCLASSES}class{$ELSE}object{$ENDIF}({$IFDEF
LAZIDE_MCK}TForm{$ELSE}TObj{$ENDIF})
Form: PControl;
KOLForm3: TKOLForm;
procedure KOLForm3BeforeCreateWindow(Sender: PObj);
procedure OnDs(aSocket: TLSocket);
procedure OnRe(aSocket: TLSocket);
procedure OnEr(const msg: string; aSocket: TLSocket);
private
{ private declarations }
public
{ public declarations }
Conexion: TLTcp;
end;
var
Form3 {$IFDEF KOL_MCK} : PForm3 {$ELSE} : TForm3 {$ENDIF} ;
{$IFDEF KOL_MCK}
procedure NewForm3( var Result: PForm3; AParent: PControl );
{$ENDIF}
implementation
{$IFDEF KOL_MCK}
{$I modulodatos2_1.inc}
{$ENDIF}{ TForm3 }
procedure TForm3.KOLForm3BeforeCreateWindow(Sender: PObj);
begin
Conexion := TLTCP.Create(nil); // create new TCP connection with no parent
component
Conexion.OnError := @OnEr; // assign callbacks
Conexion.OnReceive := @OnRe;
Conexion.OnDisconnect := @OnDs;
Conexion.Timeout := 100; // responsive enough, but won't hog cpu
ShowMessage('Componente para la conexi?n creado');
end;
procedure TForm3.OnDs(aSocket: TLSocket);
begin
ShowMessage('Lost connection');
end;
procedure TForm3.OnRe(aSocket: TLSocket);
var
s: string;
begin
if aSocket.GetMessage(s) > 0 then
ShowMessage(s);
end;
procedure TForm3.OnEr(const msg: string; aSocket: TLSocket);
begin
ShowMessage(msg); // if error occured, write it
end;
initialization
{$IFNDEF KOL_MCK} {$I modulodatos2.lrs} {$ENDIF}
end.I get the error:
ModuloDatos2.pas(48,28) Error: Variable identifier expectedAnybody help me?
Best regards.
2008/11/12 Bogus?aw Brandys
Show quoted text 22 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081209/36aa2591/attachment.html
The solution:
Delphi mode is used for MCK generated source files.
Assign event without @
Conexion.OnError := OnEr;2008/12/9 User
Show quoted text 116 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081210/7334b18a/attachment.html
