Jump to content
Sign in to follow this  
wuwuxin

Why Record pointer is not allowed as function parameter and return?

Recommended Posts

TMyFunkyRecord = record

end;


function MyFunkyFunction(AData: ^TMyFUnkyRecord): ^TMyFunkyRecord;

Delphi gives me error saying : E2029 Identifier expected but '^' found

 

I know I can define

PMyFunkyRecord = ^TMyFunkyRecord;

 

But Is the above code using pointer directly illegal?

Edited by wuwuxin

Share this post


Link to post
56 minutes ago, wuwuxin said:

 

But Is the above code using pointer directly illegal?

Yes. You have to declare a pointer type. 

Share this post


Link to post
type
 TMyFunkyRecord = record
  b:boolean;
 end;

function Something(inB:pointer):pointer;
var
 bRec:TMyFunkyRecord;
begin
 bRec:=TMyFunkyRecord(inB^);
 if bRec.b then
  beep;
 bRec.b:=false;
 result:=@bRec;
end;

var
 bRec,aRec:TMyFunkyRecord;
begin
 bRec.b:=true;
 aRec:=TMyFunkyRecord(Something(@bRec)^);
 if not aRec.b then
  beep;
end;

You can make it work with "naked" pointers. More trouble than worth to avoid declaring the pointer type. My2c.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×