I'm wondering what is wrong in the generic code below (written in Delphi 10.4.1). Moreover, is there another way to achieve the same goal ? I mean searching inside an array (I know that I should use collection). Thanks in advance !
Regards
type
TDelphiExtention = class
public
class function inside<T>(const value : T; const arr : array of T) : boolean;
end;
class function TDelphiExtention.inside<T>(const value : T; const arr : array of T) : boolean;
var
i : integer;
begin
result := true;
for i := Low(arr) to High(arr) do begin
if (arr[i] = value) then begin // E2015 Operator not applicable to this operand type !!!
exit;
end;
end;
result := false; // Not found
end;
// This one compiles like a charm... But is not generic :(
function inside(const value : integer; const arr : array of integer) : boolean;
var
i : integer;
begin
result := true;
for i := Low(arr) to High(arr) do begin
if (arr[i] = value) then begin
exit;
end;
end;
result := false; // Not found
end;