Generic records with variable array size (generics with types and numerics) lazarus / 21-General ---------------------------------------------------------------------- Fibonacci · 2024-10-17 19:19 What I want to achieve is something like this: to create a generic record and specialize it with a specific number of elements in its array. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  generic tgenrec = record    data: array[0..N-1] of T;  end; var  myrec100: specialize tgenrec; // project1.lpr(7,43) Error: Error in type definition  myrec500: specialize tgenrec; // project1.lpr(8,43) Error: Error in type definition beginend. Maybe this is possible, only I dont know about it I managed to come up with a little hack to achieve something that kind of does the job, but is limited to a having a predefined array of bytes due to the use of SizeOf(). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  arr100    = array[1..100]    of byte;  arr500    = array[1..500]    of byte;  arr1000   = array[1..1000]   of byte;  arr50000  = array[1..50000]  of byte;  arr275000 = array[1..275000] of byte;      generic tgenrec = record    data: array[0..sizeof(N)-1] of T;  end; var  myrec100: specialize tgenrec;  myrec500: specialize tgenrec; begin  writeln('sizeof myrec100 = ', sizeof(myrec100));  writeln('sizeof myrec500 = ', sizeof(myrec500));  writeln;   writeln('sizeof custom genrec = ', sizeof( specialize tgenrec    ));  writeln('sizeof custom genrec = ', sizeof( specialize tgenrec    ));  writeln('sizeof custom genrec = ', sizeof( specialize tgenrec   ));  writeln('sizeof custom genrec = ', sizeof( specialize tgenrec  ));  writeln('sizeof custom genrec = ', sizeof( specialize tgenrec ));   readln;end. What do you guys think about it? Anyone know a better solution? EDIT: One thing I should mention, I cant use dynamic arrays and SetLength() ---------------------------------------------------------------------- PascalDragon · 2024-10-17 19:33 Quote from: Fibonacci on October 17, 2024, 09:19:29 pmWhat do you guys think about it? Anyone know a better solution? In main constant parameters are supported: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program tgenconst; type  generic tgenrec = record    data: array[0..N-1] of T;  end; var  myrec100: specialize tgenrec; // project1.lpr(7,43) Error: Error in type definition  myrec500: specialize tgenrec; // project1.lpr(8,43) Error: Error in type definition beginend. In older versions you can only really use the workaround you presented. ---------------------------------------------------------------------- Fibonacci · 2024-10-17 19:41 This is great news, although I will need to upgrade this particular project to use newer version of FPC. Thanks though, didnt know it supported that in the trunk.