Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

Is there any way to turn this function into a generic function for records?

Hello guys

I have this function that Shaffler my array of record

procedure DoSwap(var s1, s2: TCadVb);
var
  tmp: TCadVb;
begin
  tmp := s1;
  s1  := s2;
  s2  := tmp;
end;


procedure ShuffleArrayCadVb;
var
 i, j : Integer;
Begin
  for i := Low(CadVb) to High(CadVb) do
  begin
    j := Random(High(CadVb) - Low(CadVb) + 1) + Low(CadVb);
    if i <> j then
       DoSwap(CadVb[i], CadVb[j]);
  end;
End;

Open in new window


But I'd like to turn it into in a generic function for any kind of record. Something like this:

procedure ShufflerArray(variable: record)

is it possible? if so, how to?

Thanks
Alex
Avatar of Mike McCracken
Mike McCracken

If you have assignment defined for the records then the code as written should work just by adding the parameter as an array of the records.

mlmcc
Avatar of hidrau

ASKER

Could you give me an example?

thanks
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hidrau

ASKER

Thanks very much for your example
It helped me a lot