NetCom7 Chat Demo

73 views Asked by At

I am trying to get the NetCom7 Chat Demo to work.

In the Git, it says:

You implement an OnHandleCommand event handler and, depending on aCmd parameter (integer), you respond the result of the command via setting the Result of the OnHandleCommand to anything you like (TBytes).

How would this look in code? I currently have a TncServerSource component on a ChatServer.exe ufrmMain.pas file called Server.

I tried the following line:

Server.OnHandleCommand()

although I don't understand what the parameters are.

1

There are 1 answers

1
SilverWarior On

OnHandleCommand is a property to store reference to an event method that will be fired when a command is received.

It works pretty much like any other events in Delphi. So if you placed the server component on your form at design-time you can then assign suitable event method from object inspector like you would any other standard Delphi event.

If you are creating your server component dynamically from code then you need to set OnHandleCommand property to reference to the suitable event method. The said event method must be object method whose format matches TncOnSourceHandleCommand that is defined in ncSources.pas unit as:

TncOnSourceHandleCommand = function(

Sender: TObject; aLine: TncLine;

aCmd: Integer; const aData: TBytes; aRequiresResult: Boolean;

const aSenderComponent, aReceiverComponent: string): TBytes of object;

So for instance you form private section you define next function

private
  function ServerOnHandleCommandEvent(Sender: TObject; aLine: TncLine; aCmd: Integer; const aData: TBytes; aRequiresResult: Boolean; const aSenderComponent, aReceiverComponent: string): TBytes of object;

After creation of your server compoennt you then assing this function to the OnHandleCommand property using:

Server.OnHandleCommand := MyForm.ServerOnHandleCommandEvent;

This is the standard way of assigning Delphi events from code at run-time instead of assigning them at design time

Finally you just write proper code in your ServerOnHandleCommandEvent method to handle received commands properly.

Since I have never used this library I'm afraid I cant show you any specific examples here.But I see that this library comes with some Demos so you might want to check those for further reference.