I looked at a Delphi example and figured I understood it but I guess I don't
This crashed badly..
-
program
Project1
;
-
-
{$mode objfpc}{$H+}
-
uses
SysUtils
,
Classes
;
-
Var
-
A
:
Array
of
Integer
;
-
L
:
Integer
;
-
begin
-
L
:
=
1
;
-
Initialize
(
A
)
;
-
DynArraySetLength
(
Pointer
(
A
)
,
TypeInfo
(
Integer
)
,
1
,
PSizeint
(
@
L
)
)
;
-
end
.
-
Doing this with 3.0.4-64bit in Winders...…….10
I looked at a Delphi example and figured I understood it but I guess I don't
This crashed badly..
-
program
Project1
;
-
-
{$mode objfpc}{$H+}
-
uses
SysUtils
,
Classes
;
-
Var
-
A
:
Array
of
Integer
;
-
L
:
Integer
;
-
begin
-
L
:
=
1
;
-
Initialize
(
A
)
;
-
DynArraySetLength
(
Pointer
(
A
)
,
TypeInfo
(
Integer
)
,
1
,
PSizeint
(
@
L
)
)
;
-
end
.
-
Doing this with 3.0.4-64bit in Winders...…….10
1. I'm not sure if the second parameter will take Typeinfo.
2. I think the last parameter should be a pointer to an array.
3. And most importantly, from the documentation:
It should never be necessary to call this function directly, the standard SetLength function should be used instead
Why do you use this function?
I looked at a Delphi example and figured I understood it but I guess I don't
This crashed badly..
-
program
Project1
;
-
-
{$mode objfpc}{$H+}
-
uses
SysUtils
,
Classes
;
-
Var
-
A
:
Array
of
Integer
;
-
L
:
Integer
;
-
begin
-
L
:
=
1
;
-
Initialize
(
A
)
;
-
DynArraySetLength
(
Pointer
(
A
)
,
TypeInfo
(
Integer
)
,
1
,
PSizeint
(
@
L
)
)
;
-
end
.
-
Doing this with 3.0.4-64bit in Winders...…….10
You need to pass the type information of the
array
, not of the
element
:
-
program
tarrtest
;
-
-
{$mode objfpc}
-
-
var
-
a
:
array
of
Integer
;
-
L
:
Integer
;
-
begin
-
L
:
=
1
;
-
DynArraySetLength
(
Pointer
(
A
)
,
TypeInfo
(
A
)
,
1
,
PSizeInt
(
@
L
)
)
;
-
Writeln
(
Length
(
A
)
)
;
-
end
.
I am well aware of set length and its workings.
I am studying the possibility of Pascal's options to configure a array
At runtime.
Basically dynamic dim count on a single array pointer.
For example at run time I may want 5 dims of various lengths and types.
Then I may only want two dims .
This info will only be known at runtime. So it's a rtti type of code without
Creating massive amounts of all types possible at design time.
Using generics isn't the answer here.
Ok,I've looked a little deeper and it seems fpc can't do what I want at the level I want so I will port over a class I wrote in Delphi some time ago to create a variable
dim size arrays
TVariableArray = Class
..
and the constructor was like this..
Constructor Create(NumberOfDims, [DimSizes, x,x,x]); etc
and with all the needed methods..
I used and open Array to parse the indexes..
What this does for me is I can assign one chunk of the array to another with a simple call..
lets say I have an array of [10,10,10,10] of something;
But I can do this
Array([2,2]) := OtherArray([3,2]);
That second dim indicates the whole chuck to move because I did not fully specify all 4 inputs
If I did specify all 4 inputs then only the single element at the end will get moved not the whole group elements.
I know this may be hard to understand but originally it was used with image processing of various formats then I kind of added other things to it.