Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 05/11/25 in all areas

  1. Wrong thread? What does [ref] attribute actually dows
  2. I’m working on a class TMethodsInjector that uses RTTI to inject a method into a method-type property (like events). If a method is already assigned, I want to combine it with the new one (same signature) and assign the result. The key part is here: if not Assigned(LOldMethod.Code) then LCombined := LNewMethod else LCombined := GenerateCombinedMethod(LRttiProperty, LOldMethod, LNewMethod); I need help implementing GenerateCombinedMethod — it should dynamically wrap both LOldMethod and LNewMethod (same structure) into a single TMethod that invokes both in order. Is there a clean way to do this using RTTI, without knowing the method signature in advance? my full class code is: unit API.Methods.Injector; interface uses System.Classes, System.SysUtils, System.Rtti, System.TypInfo; type TMethodsInjector = class public class procedure InjectMethod(aTarget: TObject; const aPropertyName: string; aMethodAddress: Pointer; aMethodData: TObject); static; end; implementation { TMethodsInjector } class procedure TMethodsInjector.InjectMethod(aTarget: TObject; const aPropertyName: string; aMethodAddress: Pointer; aMethodData: TObject); var LRttiContext: TRttiContext; LRttiType: TRttiType; LRttiProperty: TRttiProperty; LOldMethod, LNewMethod, LCombined: TMethod; begin if not Assigned(aTarget) then Exit; LRttiContext := TRttiContext.Create; try LRttiType := LRttiContext.GetType(aTarget.ClassType); LRttiProperty := LRttiType.GetProperty(aPropertyName); if Assigned(LRttiProperty) and (LRttiProperty.PropertyType.TypeKind = tkMethod) then begin LOldMethod := GetMethodProp(aTarget, aPropertyName); LNewMethod.Code := aMethodAddress; LNewMethod.Data := aMethodData; if not Assigned(LOldMethod.Code) then LCombined := LNewMethod else LCombined := GenerateCombinedMethod(LRttiProperty, LOldMethod, LNewMethod); SetMethodProp(aTarget, aPropertyName, LCombined); end else raise Exception.CreateFmt('Property %s not found or is not a method on %s', [aPropertyName, aTarget.ClassName]); finally LRttiContext.Free; end; end; end.
  3. Hi All This is a port of the dotnet/c# Console class, which makes easy to do things like set colors, move the cursor etc. https://github.com/VSoftTechnologies/VSoft.System.Console Currently only Windows supported, however it's architected so that other platforms can be added - happy to take pull requests for that if anyone wants to add other platforms. Supports Delphi XE3 or later (compiles with XE2 but encoding issues stop it from working correctly).
  4. Vincent Parrett

    VSoft.System.Console - Delphi implementation of c# Console class

    The demo is very basic - haven't had time to produce anything more extensive.
  5. Hi All I published a simple wrapper over the Windows Credential Manager Api https://github.com/VSoftTechnologies/VSoft.WindowsCredentialManager
  6. Hi All I published a simple threadpool based timer - currently for windows only but architected to be extended for other platforms (PR's invited) https://github.com/VSoftTechnologies/VSoft.ThreadpoolTimer The timer does not rely on windows messages (like TTimer) - so can be used in console applications and services.
×