添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
豁达的板栗  ·  Passing all values of ...·  2 周前    · 
低调的核桃  ·  Offsets array in a ...·  1 周前    · 
鼻子大的人字拖  ·  How to Prevent Out of ...·  1 周前    · 
安静的手套  ·  Postman flow - ...·  1 周前    · 
闷骚的树叶  ·  How Fast is .NET ...·  6 天前    · 
愤怒的显示器  ·  [API Proposal]: ...·  6 月前    · 
I looked at a Delphi example and figured I understood it but I guess I don't

This crashed badly..
Code: Pascal [Select] [+] [-]
  1. program Project1 ;
  2. {$mode objfpc}{$H+}
  3. uses SysUtils , Classes ;
  4. Var
  5. A : Array of Integer ;
  6. L : Integer ;
  7. begin
  8. L : = 1 ;
  9. Initialize ( A ) ;
  10. DynArraySetLength ( Pointer ( A ) , TypeInfo ( Integer ) , 1 , PSizeint ( @ L ) ) ;
  11. 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..
  1. program Project1 ;
  2. {$mode objfpc}{$H+}
  3. uses SysUtils , Classes ;
  4. Var
  5. A : Array of Integer ;
  6. L : Integer ;
  7. begin
  8. L : = 1 ;
  9. Initialize ( A ) ;
  10. DynArraySetLength ( Pointer ( A ) , TypeInfo ( Integer ) , 1 , PSizeint ( @ L ) ) ;
  11. 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..
  1. program Project1 ;
  2. {$mode objfpc}{$H+}
  3. uses SysUtils , Classes ;
  4. Var
  5. A : Array of Integer ;
  6. L : Integer ;
  7. begin
  8. L : = 1 ;
  9. Initialize ( A ) ;
  10. DynArraySetLength ( Pointer ( A ) , TypeInfo ( Integer ) , 1 , PSizeint ( @ L ) ) ;
  11. 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 :

  1. program tarrtest ;
  2. {$mode objfpc}
  3. var
  4. a : array of Integer ;
  5. L : Integer ;
  6. begin
  7. L : = 1 ;
  8. DynArraySetLength ( Pointer ( A ) , TypeInfo ( A ) , 1 , PSizeInt ( @ L ) ) ;
  9. Writeln ( Length ( A ) ) ;
  10. 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.