neural-api icon indicating copy to clipboard operation
neural-api copied to clipboard

Callback for write on screen (WriteLn)

Open davaponte opened this issue 4 years ago • 3 comments

It would be nice to provide a callback function to print the output messages in a GUI. For example, a TMemo. I mean the ones that are written with WriteLn.

For example:

  WriteLn
  (
    'Min/Max at 0:',  Min0:4:0,' ',Max0:4:0,
    ' at 1:', Min1:4:0,' ',Max1:4:0,
    ' at 2:', Min2:4:0,' ',Max2:4:0
  );

will be

S := Format('Min/Max at 0: %4.0f %4.0f at 1: %4.0f %4.0f at 2: %4.0f %4.0f', 
           [Min0, Max0, Min1, Max1, Min2, Max2]); 
SomeCallBack(S);

and, by default SomeCallBack point to a simple procedure with a WriteLn to don't break anything

procedure SomeCallBack(S: string);
begin
  WriteLn(S);
end;

davaponte avatar Apr 22 '21 16:04 davaponte

Hello! In the case that you are using NeuralFit, it descents from TMObject. TMObject does what you are asking for:

  TMObject = class(TObject)
    protected
      FMessageProc: TGetStrProc;
      FErrorProc: TGetStrProc;

    public
      constructor Create(); virtual;
      destructor Destroy(); override;

      procedure DefaultMessageProc(const S: string);
      procedure DefaultErrorProc(const S: string);
      procedure DefaultHideMessages(const S: string);
      procedure HideMessages();

    published
      property MessageProc: TGetStrProc read FMessageProc write FMessageProc;
      property ErrorProc: TGetStrProc read FErrorProc write FErrorProc;
  end;

You can just attribute new functions to MessageProc and to ErrorProc. TNNetNeuron, TNNetLayer and TNNet also descend from TMObject. Let me know please if there are additional messages that you would like covered by TMObject.

joaopauloschuler avatar Apr 22 '21 18:04 joaopauloschuler

There is an example here: https://github.com/joaopauloschuler/neural-api#got-too-many-console-messages

joaopauloschuler avatar Apr 22 '21 18:04 joaopauloschuler

@davaponte , please confirm areas that you need writeln replaced first. So far, all fitting writelns (except for csv creation) have been replaced.

joaopauloschuler avatar Apr 29 '21 19:04 joaopauloschuler