Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi 10.3 run button leads to strange compile/build failure

5 views
Skip to first unread message

Skybuck Flying

unread,
Jan 13, 2023, 10:38:10 AM1/13/23
to
When clicking the "Run" (F9) button in Delphi 10.3 IDE the following error occurs:

E2531 Method 'TrySetLengthV5' requires explicit type argument(s).

After cleaning the TestProgram and clicking Build the error disappears.

This is a clear sign that something is wrong with Delphi 10.3, the IDE and/or the Delphi compiler.

To see this error in action watch this youtube video, especially near the end of it, in this video I take almost an entire day of work to create TrySetLength function for dynamic arrays:

https://youtu.be/5MxN_GzZV_A

The error mostly occurs when changing code, but it also seems to occur when re-opening the project, so this is all very strange, I have no explanation for it, besides that it might be some LLVM or C/C++ compiler kind of thing... maybe the Delphi compiler consists out of multiple compilers or something or multiple stages, it is most likely related to generics/generic methods/parameterized types... something like that.

Maybe this error message is caused by my work around using var untyped parameters in a routine to work around this Delphi compiler/language limitation.

That could explain it/a lot, kinda funny that I managed to work around it, but you guys kinda didn't and did not manage to detect this work around and disallow, or maybe use it... but it's kinda strange, sometimes the work around seems to work/be allowed... and then sometimes it's not allowed/doesn't work... so that is very strange indeed ! Maybe some kind of memory corruption going on during the compiler process or language parser or instruction generator, maybe just an artifact/bug/problem in the in-memory compiler used to produce hint/warning messages etc... maybe for insight...

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

// Delphi 10.3 warning:

// I am very curious if Delphi 11 has the same problem or not...
// Delphi 11 not tested yet...

// WARNING: changing the constant array can lead to strange compile/build errors
// Error when trying to run it without rebuilding:
// [dcc32 Error] TestProgram.dpr(32): E2531 Method 'TrySetLengthV5' requires explicit type argument(s)
// SOLUTION/FIX: clean the project and build it again.

// example of compile/build problem in Delphi 10.3:

// changing from
var
vIntegerArray : array of array of array of integer;
begin
if TTrySetLengthHelper.TrySetLengthV5( vIntegerArray, [100,200,300] ) then
// ...
end

// to
var
vIntegerArray : array of array of array of array of integer;
begin
if TTrySetLengthHelper.TrySetLengthV5( vIntegerArray, [100,200,300,400] ) then
// ...
end

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

}

Bye for now,
Skybuck Flying.

Skybuck Flying

unread,
Jan 13, 2023, 11:23:48 AM1/13/23
to
I forgot to include some more context:

The original V5 leading to these strange build errors:

// "for internal use only", it's necessary:
// moved to interface section to solve following problem:
// [dcc32 Error] Unit_TrySetLength_version_005.pas(498):
// E2506 Method of parameterized type declared in interface section must not use
// local symbol 'WrapperDynArraySetLength'
procedure WrapperDynArraySetLength( var Para; typeInfo: Pointer; dimCnt: NativeInt; lengthVec: PNativeint);

// Skybuck: Use a little bit of "generic" and "typeinfo" "compiler magic ???", idea to use generics and class wrapper from ChatGPT feedback/session/answer, ChatGPT = AI from OpenAI. User "aer4af" from PascalCoin Discord chatted with ChatGPT and repeated my questions for ChatGPT.
type
EDimensionCountException = class(Exception);

TTrySetLengthHelper = class
class function TrySetLengthV5<ParameterType>
(
var ParaVar : ParameterType; const ParaLengthArray: array of integer
// var ParaVar : ParameterType; ParaLengthArray: array of integer
) : boolean;
end;

The new V6, which solves the build errors apperently, but it's less nice because it requires passing a type-parameter to the class, so it leads to more typing:

// problem no longer present in V6 ?
// conclusion: maybe type-parameterized methods are buggy in Delphi 10.3:
// apperently: type-parameterized classes less/not buggy.
procedure WrapperDynArraySetLength( var Para; typeInfo: Pointer; dimCnt: NativeInt; lengthVec: PNativeint);

// Skybuck: Use a little bit of "generic" and "typeinfo" "compiler magic ???", idea to use generics and class wrapper from ChatGPT feedback/session/answer, ChatGPT = AI from OpenAI. User "aer4af" from PascalCoin Discord chatted with ChatGPT and repeated my questions for ChatGPT.
type
EDimensionCountException = class(Exception);

// Less nice, needs more typing, try use V5 instead ! see unit version_005.
TTrySetLengthHelper<ParameterType> = class
class function TrySetLengthV6
(
var ParaVar : ParameterType; const ParaLengthArray: array of integer
// var ParaVar : ParameterType; ParaLengthArray: array of integer
) : boolean;
end;

Usage example for v6, plus it also needs explicit types to work, I guess now I know what Delphi means with it... hehe...:

type
TArrayOfArrayOfArrayOfInteger = array of array of array of array of integer; // explicit type...
var
vIntegerArray : TArrayOfArrayOfArrayOfInteger;
if TTrySetLengthHelper<TArrayOfArrayOfArrayOfInteger>.TrySetLengthV6( vIntegerArray, [100,200,300,1] ) then

Bye for now,
Skybuck.



Skybuck Flying

unread,
Jan 13, 2023, 11:48:49 AM1/13/23
to
Full information on this in these videos ;)

(Fri13Th Part 1 of 3) Delphi: Exploring the mysterious SetLength function and maybe TrySetLength problems...
https://youtu.be/rraFJfMtWXM

(Fri13Th Part 2 of 3) Delphi: Does dynarraydim exist ?
https://youtu.be/9WlIZfRPD9Q

(Fri13Th Part 3 of 3) Delphi: TrySetLength continued, DynArrayDim does exist ! =D
https://youtu.be/5MxN_GzZV_A

Bye for now,
Skybuck.
0 new messages