Reputation: 63905
I'm having some trouble with the syntax of Delphi.
I have a record:
type
TMyType = record
....
end;
and a procedure:
procedure Foo(bar:Integer);
var
ptr : ^TMyType
begin
ptr := bar //how to do this?
end;
How do I properly cast an integer to a pointer of TMyType?
Upvotes: 2
Views: 6960
Reputation: 613461
Like this:
type
PMyType = ^TMyType;
procedure Foo(bar: Integer);
var
ptr: PMyType;
begin
ptr := PMyType(bar);
end;
Upvotes: 7
Reputation: 4909
You must cast it explicitely with the new type:
type PMyType = ^TMyType;
ptr := PMyType(bar);
or
ptr := pointer(bar);
Upvotes: 3