Questions tagged [spring4d]

Spring Framework for Delphi (Spring4D for short) is an open-source code library targeting Delphi 2010 onward. It includes mostly a Dependency Injection Framework and a Base Class Library among other modules.

Filter by
Sorted by
Tagged with
0 votes
1 answer
52 views

BeforeResolve/AfterResolve in Spring4D

This is my second attempt to explain what I am trying to accomplish as I did not explain it very well before. for this Pseudo example if you have the classes to resolve setup as below; TOuter....
1 vote
1 answer
101 views

Misleading memory leak on mocked method using Spring4D

I have a class TMyClass, on which I inject interface IFileManager. In this interface there is a method GetCompanyWorkbook(const ACompanyId: System.Integer; const AStream: TStream). This method fills ...
0 votes
1 answer
67 views

In Spring4D is it not possible to register a TPair<String,String>?

The following code gives the error 'Incomplete registration for type: TPair<System.string,System.string>' but for the life of me I can't figure out what is missing. I even tried registering ...
0 votes
0 answers
31 views

Spring4D Marshmallow and TGuid fields

how could I use TGuid type fields together with the Marshmallow ORM? Methods like FindOne, for example, expect parameters of type TValue and when trying to use im TGuid, the error occurs: incompatible ...
0 votes
1 answer
86 views

spring4D dependency injector with MVP

I'm using Spring4D's dependency injector in something organized as MVP, in my view I have the interface reference of my presenter and in the create method of the presenter I have the injection of the ...
1 vote
1 answer
150 views

Delphi - Measure execution time per line of an unit

Currently I am working on performance improvements in a Delphi calculation module (bpl). In past days, I found several slow code lines. We improved execution time from 8 to 3 minutes. I found slow ...
1 vote
1 answer
128 views

How to configure dependencies in Spring4D in Delphi?

I'm reading Nick Hodges' book "Dependency Injection in DELPHI". The chapter "Registering Factories" considers this example: There is an interface: ICoffeeMaker = interface ['{...
  • 11
0 votes
1 answer
167 views

Spring4d - Constructor with interface and object as parameters

For example I have 3 frames like this: TBaseFrame = class(TFrame) end; TfraDataAwareEntity = class(TBaseFrame ) private FEntity: TObject; procedure SetEntity(const Value: TObject); { ...
0 votes
1 answer
71 views

Spring4d custom BuilderInspector not called

I have many objects registered in Spring4d container,some as Singleton.When Application shutdown almost Singletons correct call own Destroy,but some no and FastMM reports Memory leaks. I'm looking for ...
  • 23
0 votes
1 answer
72 views

Does Spring4d support inheritance of Entities?

I have two tables in my database representing an inheritance association as you can see below: table person: row_id name 1 Fred 2 Jack table customer: row_id credit_limit 1 1000....
0 votes
0 answers
96 views

Blinking caret missing in FireMonkey app when using delegate creation for MainForm

I am using the Spring4D mobile app demo code to instantiate the MainForm using the TContainer with a DelegateTo() method, as shown below. The code works fine to show the MainForm. However, the TEdit ...
  • 1,120
1 vote
1 answer
110 views

Spring4d How to make IEvent handle reference to procedure?

when implementing an Event with the definition below Spring4D will add and invoke method but will not remove handler ( with IEvent<TaskItemChangeEvent>.Remove(MyProc) ) when asked as it does not ...
0 votes
1 answer
162 views

Spring4D - When registering a type with a container is it possible to specify only the arguments you want to override in InjectConstructor()?

Given a type and registration of TTest = class public constructor Create(First, Second: IO; Other: TOther); end; GlobalContainer.RegisterType<TOther,TOther>; ...
1 vote
1 answer
270 views

Spring4D - How to resolve from container with TComponent parameter to auto factory

For an example I would like to resolve a class passing in a TComponent and TNotifyEvent such as below but the base constructor of TObject gets called and not of TMy. GlobalContainer.RegisterType<...
1 vote
0 answers
135 views

Spring4D - Is it not possible to use Weak<Shared<TObject>>?

I want to create a connection provider which issues Shared<T> and holds on to a Weak<T> but even though only 1 T instance gets created there are 2 attempts to destroy. I have included a ...
1 vote
1 answer
182 views

In Spring4D how to ResolveAll IFactory, supplying an argument from the container?

I would like to call GlobalContainer.ResolveAll<IFactory<TBob,IItem>> to return me an array of IFactories which when supplied with a TBob with return me an IItem. I have the IItems ...
1 vote
1 answer
210 views

Spring4D should not call inherited constructor if not all parameters can be resolved

We use the dependency injection framework from Spring4D and have an issue with the way it constructs objects if it cannot resolve all constructor parameters. In our case all parameters of the ...
  • 215
1 vote
1 answer
113 views

Spring4D Container Interception a-la Aspect Oriented Programming (AOP)

Goals: In the Delphi programming language. An aspect that intercepts all virtual methods. A class whose constructor requires arguments. A Dependency Injection (DI) container that BOTH Creates an ...
0 votes
2 answers
79 views

How to use lazy initialization together with DIContainer in Spring4D

I'm new to Spring4D and trying to understand how to combine DIContainers with lazy loaded objects. I think i get the concept of pushing all the creation of the objects back in the callstack to the ...
0 votes
1 answer
185 views

How does the Spring4D [inject] attribute function internally?

I'm trying to create a minimal example, that does the same thing as the Spring4D [inject] Attribute. It's supposed to automatically resolve my TOrderAdapter.FDetailsAdapter, which I want to manually ...
  • 23
1 vote
1 answer
96 views

How to test the right way the call number of a mocked method in Spring4D 1.2.2?

My test just has to check the call number of a given mocked method, nothing else. The tested class and the embedded interface: type IMyInterface = interface ( IInvokable ) ['{815BD1B0-77CB-435F-...
1 vote
1 answer
219 views

How can I mock a method call with var parameter in DUnitX and Spring4D 1.2.2

How can I mock an interface method call like procedure foo( var i_ : integer ). The tested method local variable passed as a var param, so the test must use Arg.IsAny (The test does not access it). ...
2 votes
1 answer
229 views

How to test possible memory leaks caused by references after the destruction of the tested object (DUnitX, Spring4D 1.2.2)

TMyClass contains two references. A reference to an IList<integer> and a reference to IMyInterface. The mocking of IList<integer> is not necessary. The framework probably well tested, well ...
1 vote
1 answer
190 views

Spring4D: resolve a TFrame with owner in create

I have some Frames registrated like: GlobalContainer.RegisterType<TfraBasePage, TfraSetting>(IDSettingPage); GlobalContainer.RegisterType<TfraBasePage, TfraCurrency>(IDCurrencyPage); ...
  • 2,744
0 votes
1 answer
201 views

How to mock a function that has constant array and anonymous function as parameters

I have an interface function that has a constant array and an anonymous function as parameters: TCodeword = array[0..7] of Char; TIntFunc = reference to function: Integer; IMyInterface = ...
0 votes
0 answers
54 views

Spring4D TObjectList<T> destructs if used in inherited class [duplicate]

I have created a TMyList-class that inherited from the Delphi TObjectList<T>. After changing it to a TObjectList<T> from Spring4D, I have an issue using the enumerator. I we use the ...
  • 215
1 vote
1 answer
285 views

Is it possible to create a generic Mediator for Delphi to handle generic commands

I must first admit that I am from the .Net world and am currently relearning Delphi (XE 10.x) (from back in high school - MANY years ago). In .Net, the mediator pattern is fairly well handled by ...
2 votes
1 answer
113 views

Delphi DSharp Mock is throwing an Unexpected Invocation error - why?

When using record types in a Delphi DUnit test with DSharp Mock for an interface, it is throwing and Unexpected Invocation but I cannot figure out why? I have created test console app below. program ...
  • 1,120
2 votes
1 answer
122 views

Spring4D TDistinctIterator<string>.ToArray() not working?

I want to use the Spring4D TDistinctIterator to get the distinct Values in a TDictionary. Therefore I have the following code: var d: TDictionary<Integer, String>; v: Vector<String>; ...
  • 215
3 votes
1 answer
544 views

Simple example how to Invoke TEvent with params

I'm trying to use the Spring4d framework for Delphi and I want to use the Multicast Events. While using the "normal" TNotifyEvent, it works and the handler will get called twice. uses ... ...
  • 33
1 vote
1 answer
138 views

Delphi Spring Mocking: Invalid Cast at `as` operation -- How do I solve this?

I want to test a method where an interface is cast to another interface. The cast is valid since the one interface is derived by the other. Unfortunately I receive an error at the marked line. I ...
3 votes
1 answer
160 views

Delphi Spring Mock of reference to function

I have an interface and I want to mock a function of this interface with an argument which is a reference to a function. See code exmple: unit Main; interface procedure Execute; implementation ...
2 votes
1 answer
148 views

Spring4D TMultiMap maintain IEnumerable on the fly

I create a TMultiMap instance (Spring4D Rel 1.2.2) and immediately create an IEnumerable using the Ordered function. Then I add a few items to the multimap. When using the IEnumerable created when the ...
  • 11.9k
4 votes
1 answer
365 views

Spring4D cannot sort an ordered dictionary

I need a dictionary that can be sorted. I think Spring4D TOrderedDictionary is a class implementing that but I cannot make it work: sorting doesn't work. I build a small test program showing the issue ...
  • 11.9k
1 vote
1 answer
139 views

Spring4D TMultiMap overloaded constructor not seen by compiler (Error E2250)

I'm struggling with Spring4D (1.2.2) TMultiMap generic class. I want to call an overloaded constructor and the compiler complain: "E2250 There is no overloaded version of 'Create' that can be ...
  • 11.9k
1 vote
1 answer
253 views

In Spring4D is it possible to register generic interfaces?

I have classes that have a constructor such as constructor Create(Factory: IFactory<IConnection>) When I try and register the IFactory in the container Container.RegisterType<IFactory<...
1 vote
1 answer
193 views

Spring4D field injection does not work in a TForm instance [duplicate]

I would like to use the Inject attribute of Spring4D release 1.1 just like in the sample code below. It seems the Inject attribute has no effect because the fMyResource field value is NIL in the ...
1 vote
2 answers
359 views

Smartpointers do not work well with a generic TObjectlist in Delphi

I am testing smart-pointers in Delphi 10.3 Rio using Spring4D. Here is my test program. I created a generic TObjectList and I want to add simple TObjects to this list using Shared.Make(TTestObj.Create)...
3 votes
1 answer
385 views

What is the correct way to copy the dictionary?

I need to check if there has been a change in a certain part of the application and therefore I make "copies" of the data after loading them and then compare them. One part of the comparison function ...
  • 1,515
3 votes
1 answer
199 views

Is there a Spring4D correspondent function to WillReturnDefault

Delphi-Mocks has a WillReturnDefault method when you don't care about the parameters of a function. I can't figure out how to do that with Spring4D mocking. Grateful for help!
1 vote
1 answer
263 views

Why is my implementation of TCollections.CreateObservableList for interfaces not working?

I tried to implement as @Stefan Glienke suggested in Why is Spring4D's IList OnChanged event not fired? an ObservableList for interfaces. This version should implement an observable list of ...
1 vote
1 answer
393 views

Why is Spring4D's IList<T> OnChanged event not fired when the object changes (while Add and Remove fire the event)?

I modified @Stefan Glienkes example from Notify the TObjectList when Object changed to use IList, since I am using interfaced objects in my list. In the event handler, I can handle caAdded and ...
  • 45
0 votes
0 answers
188 views

Getting RTTI information on a smart pointer

Using Spring, when I declare a smart pointer for a record SmartPerson = IShared<Pperson>; And then create it Smartperson := Shared<PPerson>.Make; *by the way, think this is really ...
0 votes
1 answer
67 views

Is there any delayed MultiCast-Event, which is able to be interruptable?

I am looking for an interruptable, delayed event, which I hope could be already part of Spring4D, or easily implemented there. What would be best way anyway, to achieve this ? Probably the Event ...
2 votes
1 answer
214 views

Can't use default parametr values with comparer in Spring4D

I'm not sure if this is some generic problem or it's because of Spring4D implementation, but I can't use default parameter values for creating comparer. type TMyClass = class class function ...
  • 1,515
1 vote
1 answer
225 views

Unsatisfied constructor on type

playing around with the Dependency Injection Framework from Spring4D. At moment I try to use DynamicAbstractFactories. In the Test are 2 classes and factories: IOrderShipper and IOrderShipperFactory ...
  • 524
0 votes
1 answer
347 views

Spring4D latest not compatible with DSharp?

I downloaded Spring4D "sglienke-spring4d-ca8037a2fdec.zip" from this link https://bitbucket.org/sglienke/spring4d/downloads/. And I downloaded DSharp "sglienke-dsharp-2eae62962442.zip" from this link ...
1 vote
2 answers
460 views

How to assign an OleVariant with RTTI? // Convert an OleVariant or a Variant to a TValue with specific TTypeKind or TRTTIType in mind?

I have an OleVariant or a Variant value that, for example, was read with IXMLNode.GetAttributeNS, making it a "String" (varOleStr or varString), and I would like to write that value with, for example, ...
  • 651
0 votes
1 answer
154 views

Memory issues when using spring.Nullable with DUnitX

Recently at my company we tried to use DUnitX with all it's blessings to test classes we wrote. Since those classes reflect entities in database all fields have to accept null values as well as ...
10 votes
1 answer
330 views

IList<T> crashes when T is an event handler?

It appears to me that IList can NOT take Event handler as its element. The program has access violation $C00000005 on PROGRAM exit. Everything is fine if I use Delphi RTL's TList. The access ...