Skybuck Flying
2022-08-29 06:51:45 UTC
See comments at updated comment section.
unit Unit_TrySetLength_version_003;
{
TrySetLength
version 0.01 created on 5 juli 2006 by Harald Houppermans.
Usage of TrySetLength routine:
Typecast any array to a Tarray type so that it can be passed to
the TrySetLength function. For now the TrySetLength function can only be used
to specify a single dimension. Multi dimension length specifiers not supported.
}
{
version 0.02 created on 5 juli 2006 by Harald Houppermans.
+ Conditional inline directive added (INLINE_ON)
}
{
version 0.03 created on 5 juli 2006 by Harald Houppermans.
- inline removed
}
{
version 0.03 updated comments on 29 august 2022 by Harald Houppermans.
SOMEHOW THIS CODE IS:
1. BOMBING IN DELPHI 10.3
2. IT ESPECIALLY BOMBS FOR DYNAMIC ARRAYS OF NON-CLASS TYPES, FOR EXAMPLE
RECORDS ?!? ARRAY OF RECORDS ?! WHY AND WTF ?!
MAYBE THIS CODE WAS ONLY MENT TO WORK WITH CLASSES ?!?! WHY IT DON'T WORK
WITH OTHER STUFF ?! BEWARE !?!?!?!?!
THIS PRODUCED ACCESS VIOLATION:
USING IT REQUIRES A TYPE TO TARRAY WHICH IS ARRAY OF TvarRec
TrySetLength( TArray(YourDynamicArrayOfSomeType), 1000 );
Maybe this type casting is causing some kind of issue ?
Maybe something changes internally because of generics ? or they not
included ?! NO IDEA.
Maybe it cannot handle records which contain arrays of records ? or
static arrays or something ?! It's WEIRD ?!
}
interface
type
Tarray = array of TvarRec;
function TrySetLength( var ParaVar : Tarray; const ParaNewLength : integer ) : boolean;
implementation
function TrySetLength( var ParaVar : Tarray; const ParaNewLength : integer ) : boolean;
begin
try
SetLength( ParaVar, ParaNewLength );
result := true;
except
result := false;
end;
end;
end.
Bye,
Skybuck.
unit Unit_TrySetLength_version_003;
{
TrySetLength
version 0.01 created on 5 juli 2006 by Harald Houppermans.
Usage of TrySetLength routine:
Typecast any array to a Tarray type so that it can be passed to
the TrySetLength function. For now the TrySetLength function can only be used
to specify a single dimension. Multi dimension length specifiers not supported.
}
{
version 0.02 created on 5 juli 2006 by Harald Houppermans.
+ Conditional inline directive added (INLINE_ON)
}
{
version 0.03 created on 5 juli 2006 by Harald Houppermans.
- inline removed
}
{
version 0.03 updated comments on 29 august 2022 by Harald Houppermans.
SOMEHOW THIS CODE IS:
1. BOMBING IN DELPHI 10.3
2. IT ESPECIALLY BOMBS FOR DYNAMIC ARRAYS OF NON-CLASS TYPES, FOR EXAMPLE
RECORDS ?!? ARRAY OF RECORDS ?! WHY AND WTF ?!
MAYBE THIS CODE WAS ONLY MENT TO WORK WITH CLASSES ?!?! WHY IT DON'T WORK
WITH OTHER STUFF ?! BEWARE !?!?!?!?!
THIS PRODUCED ACCESS VIOLATION:
USING IT REQUIRES A TYPE TO TARRAY WHICH IS ARRAY OF TvarRec
TrySetLength( TArray(YourDynamicArrayOfSomeType), 1000 );
Maybe this type casting is causing some kind of issue ?
Maybe something changes internally because of generics ? or they not
included ?! NO IDEA.
Maybe it cannot handle records which contain arrays of records ? or
static arrays or something ?! It's WEIRD ?!
}
interface
type
Tarray = array of TvarRec;
function TrySetLength( var ParaVar : Tarray; const ParaNewLength : integer ) : boolean;
implementation
function TrySetLength( var ParaVar : Tarray; const ParaNewLength : integer ) : boolean;
begin
try
SetLength( ParaVar, ParaNewLength );
result := true;
except
result := false;
end;
end;
end.
Bye,
Skybuck.