Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 05/06/19 in Posts

  1. uligerhardt

    Anon methods passed as event handlers?

    No, that's why I'm talking about class methods. You can use them like this: type TMyEventHandler = class public class procedure OnError(const AMessage: string); end; Something.OnError := TMyEventHandler.OnError; The method has to be non-static to provide the needed Self parameter.
  2. Or you could hook the editors onkeypress event. In both cases be careful, you have to clean up before your module gets unloaded/dumped.
  3. Stefan Glienke

    Using GetMethod functions in the .NET COM interop

    Probably by calling Type.GetType(string)
  4. David Heffernan

    Anon methods passed as event handlers?

    It seems to make sense in other languages, like C# to give one example. The very way you talk about it is symptomatic of the problem. Talking about implementation details. Clearly there has to be an implentarion, but programmers by and large want to be shielded from these details.
  5. David Heffernan

    Anon methods passed as event handlers?

    David is making a good point here. If Emba were starting from scratch here, would they end up with all these different incompatible procedural types? I doubt it.
  6. New LMD 2019.6 installers are available now! The complete VCL package includes more than 750 VCL components including popular packages like LMD DockingPack and LMD DialogPack (Delphi/C++Builder 6 and better). Main change besides several bugfixes is an extensive update for the TLMDStatusBar commponent in LMD-Tools (Full support for VCL Styles, OldStyle is now disabled by default, besides the previously available custom panels feature (which allows to place any control on a status panel) many new predefined panels were added (including Glyph support, DB features etc.)). Review changes of this release on history page:http://wiki.lmd.de/index.php/LMD_2019_-_History Find summary of all changes in LMD 2019 on What's New Page:http://wiki.lmd.de/index.php/LMD_VCL_2019_-_NewsCheck the new trials and compiled Exe-Demos athttps://www.lmd.de/downloads For example the LMD DockingPack demo:http://files.lmd.de/downloads/lmd2017vcl/DockingPack_Demo.zipTo learn more about other LMD products visit the General Product Page:https://www.lmd.de/products/vcl/lmdvclAll products are based on LMD 2019 platform. For more info about LMD 2019 platform checkhttp://wiki.lmd.de/index.php/LMD_VCL_-_DescriptionFeature Matrix of all LMD VCL products:https://www.lmd.de/feature-matrixIf you are interested in purchasing check out the Order Page:http://www.lmd.de/shopping If any questions are left, please contact us at mail@lmdsupport.com!
  7. Stefan Glienke

    Rio 10.3.1 IDE Compiler Error

    Look for code that uses type inference - if that only happens with DUnitX config, then look for Assert.something calls
  8. Like the events of most other components, the events of Indy components expect class methods, not standalone functions. You could go the way that others have recommended, where creating a TDataModule at design-time and using it at run-time would be the easiest. But, even if you were to simply write a class in code to wrap the events, note that you don't actually need to instantiate such a class at run-time, you can declare its methods with the class directive instead, eg: program IndyConsoleApp; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, IdContext, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer, IdGlobal; var IdTCPServer1: TIdTCPServer; procedure ShowStartServerdMessage; begin WriteLn('START SERVER @' + TimeToStr(now)); end; procedure StopStartServerdMessage; begin WriteLn('STOP SERVER @' + TimeToStr(now)); end; type TCPServerEvents = class class procedure OnExecute(AContext: TIdContext); end; class procedure TCPServerEvents.OnExecute(AContext: TIdContext); var LLine: String; begin LLine := AContext.Connection.IOHandler.ReadLn(); writeln(LLine); AContext.Connection.IOHandler.WriteLn('OK'); end; begin try IdTCPServer1 := TIdTCPServer.Create; try with IdTCPServer1.Bindings.Add do begin IP := '127.0.0.1'; Port := 6000; end; IdTCPServer1.OnExecute := TCPServerEvents.OnExecute; IdTCPServer1.Active := True; try ShowStartServerdMessage; Readln; finally IdTCPServer1.Active := False; StopStartServerdMessage; end; finally IdTCPServer1.Free; end; except on E: Exception do WriteLn(E.ClassName, ': ', E.Message); end; end. However, there IS actually a way to use a standalone function instead, but it involves a little trickery using Delphi's TMethod record: program IndyConsoleApp; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, IdContext, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer, IdGlobal; var IdTCPServer1: TIdTCPServer; procedure ShowStartServerdMessage; begin WriteLn('START SERVER @' + TimeToStr(now)); end; procedure StopStartServerdMessage; begin WriteLn('STOP SERVER @' + TimeToStr(now)); end; procedure TCPServerExecute(ASelf: Pointer; AContext: TIdContext); // NOTE THE EXTRA PARAMETER! var LLine: String; begin LLine := AContext.Connection.IOHandler.ReadLn(); WriteLn(LLine); AContext.Connection.IOHandler.WriteLn('OK'); end; var ExecuteFct: TMethod; begin try IdTCPServer1 := TIdTCPServer.Create; try with IdTCPServer1.Bindings.Add do begin IP := '127.0.0.1'; Port := 6000; end; ExecuteFct.Data := nil; // or anything you want to pass to the ASelf parameter... ExecuteFct.Code := @TCPServerExecute; IdTCPServer1.OnExecute := TIdServerThreadEvent(ExecuteFct); IdTCPServer1.Active := True; try ShowStartServerdMessage; Readln; finally IdTCPServer1.Active := False; StopStartServerdMessage; end; finally IdTCPServer1.Free; end; except on E: Exception do WriteLn(E.ClassName, ': ', E.Message); end; end.
×