Jump to content

egroups

Members
  • Content Count

    20
  • Joined

  • Last visited

Posts posted by egroups


  1. On 2/28/2024 at 4:49 PM, Stefan Glienke said:

    The usual reasons for memory leaks that I have seen:

    - not using interfaces as service types

    - registered components are not inheriting from TInterfacedObject (or some other properly reference counting implementing class)

    - in combination with the previous point when using AsSingleton without explicitly stating a value for TRefCounting to tell the container if the class implements ref counting or not

    - injected dependencies are further passed to and held by other services creating cross or cyclic references (use LeakCheck to better find them than just looking through the huge list that FastMM produces, ideally in a smaller scope, 2GB memleak log sounds a bit huge)

     

    You can log some of that information by iterating .Registry.FindAll from the container instance and checking various properties of each TComponentModel such as ComponentType, Services and LifetimeType.

    Thanks Stefan,I try LeakCheck and Registry.FindAll


  2. Hi there,

    I convert legacy application to using Spring4D container for dependency injection.

    For memory leaks using FastMM4.

    Occasionally appear memory leak in different places and I solve them gradually.

    The problem is with the use of dependency injections, FatsMM generates very large log file (aka 2GB) and very long time.Some registered class in container not call Destroy (memory leaks in dependency graph).

    Is there any way to more easily and quickly detect places where there is a memory leak?

    Any extension for container or different method?


  3. if LMethod.IsClassMethod and LMethod.IsStatic then
        begin
          {$IF CompilerVersion >= 35}
          if not Assigned(FGetter) and (LMethod.MethodKind = mkClassFunction)
            and LMethod.HasName('Get' + FDependencyProperty.Name) then
          {$ELSE}
          if not Assigned(FGetter) and (LMethod.MethodKind = mkClassFunction)
            and SameText(LMethod.Name, 'Get' + Name) then
          {$IFEND}

    This work for me.


  4. I have many registrations in spring4d container.

    In DEBUG mode start application OK but in RELEASE before show first SplashScreen I get error: Cannot resolve type: xxxxType

    Hi can I quickly identify where is problem?

    Cannot use brakpoints,container logging etc.

    My xxxxType is very much used accros application and inject in many places.


  5. 16 hours ago, Angus Robertson said:

    Not much error handling for opening the file, it might not exist or be protected, or whether you read it correctly, I set all the output parameters for PKCS12_parse to nil before calling it, unless this is a very old Delphi your password is not AnsiString, just a few things to try, OpenSSL error handling might give you some ideas.  Your last line does not work with any newer versions of OpenSSL, and 1.0.2 is out of support in four weeks.

     

    ICS has a TX509 certificate class that does all this for you, including getting all certificate fields, and another that renews it automatically before expiry.  You can use these with internet libraries. 

     

    Angus

     

    Thanks for your answer.I tried ICS and now working for me.


  6. Hi,

    I need get Expiration Date from certificate.

    I tryed this code with libeay32:

    function TSOpenSSL.CertificatePKCS12Expirate(const pFileName, pPassword:
        string): TDateTime;
    var
      buffer: Array [0..1023] of char;
      ca: pSTACK_OFX509;
      certfile: pBIO;
      lTime: pASN1_TIME;
      p12: pPKCS12;
      pCertificate: pX509;
      pkey: pEVP_PKEY;
    begin
      certfile:=BIO_new(BIO_s_file());
      if (certfile = nil) then raise Exception.Create('Error creating BIO.');
    
      BIO_read_filename(certfile, PAnsiChar(UTF8Encode(pFileName)));
    
      p12:=d2i_PKCS12_bio(certfile, nil);
      PKCS12_parse(p12, PAnsiChar(pPassword), pkey, pCertificate, ca);
      //here is allways pCertificate=nil
      PKCS12_free(p12);
      p12:=nil;
    
      BIO_free(certfile);
    
      if (pCertificate = nil) then raise Exception.Create('Unable to read certificate from file ' + pFileName + '.');
      lTime:=pCertificate.cert_info.validity.notAfter;
    end;

    I wrote in comment where pCertificate is allways nil and I cannot of course read any data from this.

    Why?

    Password I have correct.I tryed this on some certificate files.


  7. I tryed Bind(srcViewModel.Container,'DataSource',dstDBGrid,'DataSource'),no error,but DataSource not binded,DBGrid.DataSource not Assigned.

    In srcViewModel I call

    TBindings.Notify(self,'Container'); //nothing
    TBindings.Notify(self,'Container.DataSource'); //nothing


  8. Hello,

    I tryed generate LiveBindings by Code.

    I am used from example this code

    procedure Bind(const Source: TObject; const SourcePropertyName: string; const Target: TObject; const TargetPropertyName: string);
    var
      lSrcProperty,lDstProperty:string;
      lAssocInput,lAssocOutput:IScope;
      lManaged:TBindingExpression;
    begin
      lAssocInput:=TBindings.CreateAssociationScope([Associate(Source,'Src')]);
      lAssocOutput:=TBindings.CreateAssociationScope([Associate(Target, 'Dst')]);
      lSrcProperty:='Src.'+ SourcePropertyName;
      lDstProperty:='Dst.'+ TargetPropertyName;
      lManaged:=TBindings.CreateManagedBinding(
        [lAssocInput],lSrcProperty,
        [lAssocOutput],lDstProperty,
        nil, nil,[coNotifyOutput]);
      BindingExpressions.Add(lManaged);
    end;
    

    This is OK if I used for example:

    Bind(srcViewModel,'String',dstEdit,'Text')
    Bind(srcViewModel,'Number',dstEdit,'Text')
    Bind(srcViewModel,'Boolean',dstCheckBox,'Checked')
    

    But I have srcViewModel.Container.DataSource and on form DBGrid (I NEED DBGrid).

    When I Use

    Bind(srcViewModel,'Container.DataSource',dstDBGrid,'DataSource')

    is OK,but when I use TBindings.Notify application says DBGrid don't have property DataSource.

     

    Why?

    What problem when I binding DataSource to DataSource?

×