[fpc-pascal]how to assign a value to an untyped variable

Michael Van Canneyt michael.vancanneyt at wisa.be
Fri Jul 11 14:46:13 CEST 2003


On Fri, 11 Jul 2003, ZINTEL Gerhard wrote:

> hello list members,
>
> could anyone of you give me a hint how to assign a value to an untyped
> variable parameter of a procedure. E.G. in the following procedure:
>
> procedure test(var value);
> var r : real;
> begin
>   r := 1.0;
>   value := real;	// does not work
> end;
>
> which type to be used for a type cast (that is not allowed for the left
> side) or how to use an address operator to manage it?

One way would be:

procedure test(var value);

Type
  PReal = ^real;

var
  r : real;

begin
  r := 1.0;
  PReal(@value)^ := r;
end;

Another way would be:

procedure test(var value);

Type
  PReal = ^real;

var
  P : PReal;
  r : real;

begin
  P:=@value;
  r := 1.0;
  P^ := r;
end;

It may be more suitable if you need more than one operation or when R is
an arraytype.

Michael.









More information about the fpc-pascal mailing list