is there a possibility to declare something like
Code: Select all
Type
TPWM0_MODE = (PWM0_MODE_00, PWM0_MODE_01);
...
Procedure PWM0_Init(wave_mode : TPWM0_MODE; prescaler : Byte);
Thank you
best regards
Elmar
Code: Select all
Type
TPWM0_MODE = (PWM0_MODE_00, PWM0_MODE_01);
...
Procedure PWM0_Init(wave_mode : TPWM0_MODE; prescaler : Byte);
Code: Select all
Program MyProject;
type TPWM0_MODE = record
PWM0_MODE_00 : byte;
PWM0_MODE_01 : byte;
end;
var mode : TPWM0_MODE;
var test0, test1 : byte;
Procedure PWM0_Init(var wave_mode : TPWM0_MODE; prescaler : Byte);
begin
test0 := mode.PWM0_MODE_00;
test1 := mode.PWM0_MODE_01;
end;
begin
mode.PWM0_MODE_00 := 0xAA;
mode.PWM0_MODE_01 := 0xBB;
PWM0_Init(mode, 1);
end.
Code: Select all
Procedure PWM0_Init(var wave_mode : TPWM0_MODE; prescaler : Byte);
begin
Case wavemode Of
... : Begin
End;
End;
end;
Hello Elmar,elmar.faber wrote:Thank you Filip for your reply,
but I think it isn't what I mean. In your case ther are no posibillity to define
a construction like:In this way I can define one wave mode for the PWM Channel.Code: Select all
Type TPWM0_MODE = (PWM0_MODE_00, PWM0_MODE_01); ... Procedure PWM0_Init(var wave_mode : TPWM0_MODE; prescaler : Byte); begin Case wavemode Of ... : Begin End; End; end;
Code: Select all
type
TPWM0_MODE = byte;
const
PWM0_MODE_00 = 0;
PWM0_MODE_01 = 1;
Procedure PWM0_Init(var wave_mode : TPWM0_MODE; prescaler : Byte);
begin
Case wave_mode Of
PWM0_MODE_00 : Begin
End;
End;
end;
Yes, of course...elmar.faber wrote:yes it's another way thats right but all this don't avoid that
I could change the params of the procedure.
This declaration would avoid that I take the wrong params:
[...]
That's my intension for my question
Yes. Here's one way to force compiler to cry at compile time with an inversion of parameters:Dany wrote:There is no enumeration type in mP, so you should use the method Olso suggested. mP is no so strong typed as it could be...
Code: Select all
//Type TPWM0_MODE = (PWM0_MODE_00, PWM0_MODE_01);
//Procedure PWM0_Init(wave_mode : TPWM0_MODE; prescaler : Byte);
const
PWM0_PRESCALER_0 = 0;
PWM0_PRESCALER_1 = 1;
type
TPWM0_MODE = function: byte;
pTPWM0_MODE = ^TPWM0_MODE;
var
prescaler: byte;
function PWM0_MODE_00: byte; begin result := 0 end;
function PWM0_MODE_01: byte; begin result := 1 end;
procedure proc(wave_mode: pTPWM0_MODE; prescaler: byte);
begin
...
end;
begin
...
proc(@PWM0_MODE_00, PWM0_PRESCALER_1); // accepted
proc(@PWM0_PRESCALER_1, PWM0_MODE_00); // compiler error: 'Operator "@" not applicable to these operands'
...
end;