Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sugestão para viabilizar o uso de procedure anônima no método Listen (com FPC) #361

Open
edsontmarques opened this issue Sep 19, 2023 · 5 comments
Labels
enhancement New feature or request lazarus

Comments

@edsontmarques
Copy link

Similar ao que já se encontra na unit Horse.Callback, sugeriria avaliar a possibilidade de alterar a Horse.Proc da seguinte forma:

unit Horse.Proc;

{$IF DEFINED(FPC)}
  {$MODE DELPHI}{$H+}
  {$IF DEFINED(HORSE_FPC_FUNCTIONREFERENCES)}
    {$MODESWITCH FUNCTIONREFERENCES+}
  {$ENDIF}
{$ENDIF}

interface

{$IF NOT DEFINED(FPC)}
uses
  System.SysUtils;
{$ENDIF}

type
  TNextProc = {$IF DEFINED(FPC)}procedure of object{$ELSE}System.SysUtils.TProc{$ENDIF};
  TProc = {$IF DEFINED(FPC)}{$IF DEFINED(HORSE_FPC_FUNCTIONREFERENCES)}reference to {$ENDIF}procedure{$ELSE}System.SysUtils.TProc{$ENDIF};

  {$IF DEFINED(FPC)}
    TProc<T> = {$IF DEFINED(HORSE_FPC_FUNCTIONREFERENCES)}reference to {$ENDIF}procedure(Arg1: T);
  {$ENDIF}

implementation

end.
@viniciussanchez
Copy link
Member

Boa tarde... poderia dar um exemplo de uso? E qual o erro você tem hoje?
Porque na versão atual, já é possível o uso, se eu entendi bem:

image

@edsontmarques
Copy link
Author

Boa tarde!
A ideia seria viabilizar a seguinte situação:

program Teste;

{$IFDEF FPC}
  {$MODE DELPHI}{$H+}
  {$MODESWITCH ANONYMOUSFUNCTIONS+}
{$ENDIF}

interface

implementation

uses
  SysUtils;
  
begin
  ...
  THorse.Listen(9000,
    procedure
    begin
      WriteLn(Format('Server active on port %d', [THorse.Port]));
    end);
end;        

end.

Com o que sugeri (que foi o que eu implementei aqui no meu checkout local do Horse (trunk)), eu consigo usar procedure anônima direto dentro do Listen, o que é possível com o FPC 3.2.2.

@viniciussanchez
Copy link
Member

Assim, legal... manda um Pull request entao pra gente, o que acha? dai seu nome aparece como contribuidor tambem do projeto

@edsontmarques
Copy link
Author

Seria uma honra!
Vou preparar aqui!

@viniciussanchez
Copy link
Member

Vlw

@viniciussanchez viniciussanchez added the enhancement New feature or request label Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lazarus
Projects
Status: Todo
Development

No branches or pull requests

2 participants