RandSeed not working?

procedure RandSeed();
var datum: TDateTime;
var hodina,minuta,sekunda,milisekunda: Word;
begin
  DecodeTime(datum,hodina,minuta,sekunda,milisekunda);
  RandSeed := milisekunda;
end;

This code does not work. He says that “the left side cannot be assigned” when I try to compile it. Does anyone know why? Thank.

EDIT: I changed my code as follows based on your advice, and now it works, thanks a lot!

procedure RandSeed();
var hodina,minuta,sekunda,milisekunda: Word;
begin
  DecodeTime(now,hodina,minuta,sekunda,milisekunda);
  System.RandSeed := milisekunda;
end;
+3
source share
2 answers

Two problems: firstly, as RRUZ mentions, you have a name conflict with a predefined one System.RandSeed. The conflict is caused by the fact that you are trying to return a value from a procedure. (See below.)

The second reason is that, as I said, you are trying to return a value from a procedure. You need a function.

function RandSeed: Word;
var 
  datum: TDateTime;
var 
  hodina,minuta,sekunda,milisekunda: Word;
begin
  DecodeTime(datum,hodina,minuta,sekunda,milisekunda);
  RandSeed := milisekunda;
  // Better (and more modern) would be
  // Result := milisekunda;
end;

RandSeed , . , RandSeed, ::

System.RandSeed := millisekunda;
+3

RandSeed, , System.RandSeed, RandSeed .

+7

All Articles