Reputation: 1147
procedure RandSeed();
var datum: TDateTime;
var hodina,minuta,sekunda,milisekunda: Word;
begin
DecodeTime(datum,hodina,minuta,sekunda,milisekunda);
RandSeed := milisekunda;
end;
This code doesn't work. It says 'left side cannot be assigned to' when I try compiling it. Anyone knows why? Thanks.
EDIT: I've changed my code as following based on your tips and it works now, thanks a lot!
procedure RandSeed();
var hodina,minuta,sekunda,milisekunda: Word;
begin
DecodeTime(now,hodina,minuta,sekunda,milisekunda);
System.RandSeed := milisekunda;
end;
Upvotes: 3
Views: 497
Reputation: 125688
Two problems: First, as RRUZ mentions, you have a naming conflict with the predefined System.RandSeed
. The conflict is caused by the fact you're trying to return a value from a procedure. (See below.)
The second reason is, as I said, you're trying to return a value from a procedure. You need a function instead.
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;
If your intent is to replace the internal RandSeed
variable with your own function, this will work. If your intent is just to use your function to assign a value to the existing RandSeed
variable, change your procedure to contain::
System.RandSeed := millisekunda;
Upvotes: 3