You are not logged in.
Hello!
If I wrote the code (Delphi XE and actual mORMot) according to the documentation, i.e.:
var
DA : IObjectDynArray; // defined BEFORE the dynamic array itself
A : array of TOA;
i : integer;
begin
DA := TObjectDynArrayWrapper.Create(A);
for I := 1 to 10 do
DA.Add(TOA.Create(IntToStr(I)));
end;
I'm getting an exception: You MUST define your IObjectDynArray field BEFORE the corresponding dynamic array.
If I wrote:
var
A : array of TOA;
DA : IObjectDynArray; // defined BEFORE the dynamic array itself
i : integer;
begin
DA := TObjectDynArrayWrapper.Create(A);
for I := 1 to 10 do
DA.Add(TOA.Create(IntToStr(I)));
end;
Everything is OK.
This is a bug in manual or what?
In addition, please add the Compact method to DynArrayWrapper. Something like that:
IObjectDynArrayEx = interface(IObjectDynArray)
['{FD8E284A-9585-4FE8-96CB-0FB98350731C}']
procedure Compact;
end;
TObjectDynArrayWrapperEx = class(TObjectDynArrayWrapper, IObjectDynArrayEx)
public
procedure Compact;
end;
implementation
{ TObjectDynArrayWrapperEx }
procedure TObjectDynArrayWrapperEx.Compact;
begin
SetLength(TObjectDynArray(fValue^), Count);
end;
Offline
The notion of "before" is relative to the instance creation time.
It is not "before" in the list of stack-allocated variable, it is "before" the actual allocation.
Online
I've just introduced TObjectDynArrayWrapper.Slice as you requested.
Online
I've just introduced TObjectDynArrayWrapper.Slice as you requested.
Thank you!
BTW - Slice?
Are you sure it's the right name? ;-)
In my opinion, it's more about compacting this array than slicing it...
Last edited by wloochacz (2017-11-22 20:23:47)
Offline
Usually, Slice is about a portion of an array.
https://developer.mozilla.org/en-US/doc … rray/slice
https://docs.microsoft.com/en-us/cpp/st … lice-class
https://dlang.org/d-array-article.html
Offline
About naming: Ruby uses Array.Compact() for this function.
Last edited by Junior/RO (2017-11-23 15:30:32)
Offline
Maybe Array.Trim()?
Offline