Jump to content

Search the Community

Showing results for tags 'anonymous methods'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 2 results

  1. The usual way of creating an event handler in Delphi is to double-click the right-hand field in the Events tab of the Object Inspector. This creates a method with the proper signature; when the form is loaded, the OnXyzEvent is assigned the method name: FOnXyzEvent := aForm.XyzEvent; In theory, it should be possible to do something like this for a typical event handler: FOnXyzEvent := procedure(Sender: TObject) begin doSomething; end; However, I have a TpgScript object that has an AfterExecute event with this signature: procedure TpgScriptEx.DoOnAfterExecute(Sender: TObject; SQL: string); begin // end; FScript.AfterExecute := DoOnAfterExecute; // this works fine // but for this, the compiler complains: // [dcc32 Error] myfile.pas(1258): E2010 Incompatible types: 'TAfterStatementExecuteEvent' and 'Procedure' FScript.AfterExecute := procedure (Sender: TObject; SQL: string) begin // end; If I try casting the procedure, I get an Invalid Cast error. This seems like it should be a compiler bug. Is there a workaround for this?
  2. Code that looks correct, and appear to compile alright, but which doesn't execute well. Can you spot the error? See my blog post for a link to a SCCE. var Handler: THandlerClass; hType: THandlers; begin Broker.Clear; for hType in [foo, bar] do begin case hType of foo: Handler := TFoo.Create; bar: Handler := TBar.Create; end; Broker.AddHandler(Handler.OnHandle); end; end; https://larsfosdal.blog/2019/02/08/delphi-pitfalls-of-anonymous-methods-and-capture/
×