Forum > Beginners

var instead of const

(1/3) > >>

coradi:
If i try this

--- Code: ---Function LED_Blink(const i : Word):BYTE;
Begin
  Led_Status := not Led_Status;
  delay_ms(i);
  result:=0;
end;
--- End code ---

I got the message
"45 304 Syntax error: Expected "constant expression" but "complex expression" found RTC_DS3234.mpas
45 305 Argument is out of range "i. Argument must be greater than or equal to 0." RTC_DS3234.mpas


Delay is waiting for an constand, but I want to use a variable.
How can I do that?

rvk:

--- Quote from: coradi on October 30, 2023, 09:51:01 pm ---I got the message
"45 304 Syntax error: Expected "constant expression" but "complex expression" found RTC_DS3234.mpas
45 305 Argument is out of range "i. Argument must be greater than or equal to 0." RTC_DS3234.mpas

Delay is waiting for an constand, but I want to use a variable.
How can I do that?

--- End quote ---
You can use a variable. You just can't use a "complex expression".

How did you call this function?

coradi:
I call it with LED_blink(100);

No, variable isn't allowed:-(
This works, but is there an shorter solution?

--- Code: ---Function LED_Blink(i : Word):BYTE;
var n : word;
Begin
  Led_Status := not Led_Status;
  For n:=1 TO i DO
  Begin
  delay_ms(1);
  end;
  result:=0;
end;

--- End code ---

rvk:
Show the relevant code.
So delay_ms() and the call to LED_Blink().

And mention what mode you are in.
(TP, Delphi, ObjFpc ?)

PascalDragon:

--- Quote from: coradi on October 30, 2023, 09:51:01 pm ---If i try this

--- Code: ---Function LED_Blink(const i : Word):BYTE;
Begin
  Led_Status := not Led_Status;
  delay_ms(i);
  result:=0;
end;
--- End code ---

I got the message
"45 304 Syntax error: Expected "constant expression" but "complex expression" found RTC_DS3234.mpas
45 305 Argument is out of range "i. Argument must be greater than or equal to 0." RTC_DS3234.mpas

--- End quote ---

This does not look like an error message created by Free Pascal. Please ask that question on a corresponding site for the compiler you're using (which seems to be mikroPascal according to the file extension).

Navigation

[0] Message Index

[#] Next page

Go to full version