Jump to content
Sign in to follow this  
DavidRM

Assigning a Record Type Function Result to a Variant

Recommended Posts

This...

procedure PXTeamCreate(aTeam: TTeamStruct; aCallback: TPXMessageCallback);
begin
  var aData: Variant := new JObject;
  aData.team := aTeam.Save;
  PXSend(PXM_TEAMCREATE, aData, aCallback);
end;

Compiles to this:

function PXTeamCreate(aTeam$4, aCallback$4) {
   var aData$5;
   aData$5 = {};
   aData$5.team = {};
   PXSend(122,aData$5,aCallback$4);
};

All I can figure is that TTeamStruct.Save returns a *record* type, and somehow the poor result is being scoped out of existence before it even gets a chance.

 

function TTeamStruct.Save: TTeamXfer;
begin
  Result.TeamID :=  TeamID;
  Result.Name := Name;
  Result.Desc := Desc;
  Result.Web := Web;
  Result.Bonus := Bonus;
  Result.Shots := Shots;
  Result.Splats := Splats;
  Result.BonusCurrent := BonusCurrent;
  Result.ShotsCurrent := ShotsCurrent;
  Result.SplatsCurrent := SplatsCurrent;
end;

  TTeamXfer = record
    TeamID: integer; external 'teamID';
    Name: string; external 'name';
    Desc: string; external 'desc';
    Web: string; external 'web';
    Bonus: integer; external 'bonus';
    Shots: integer; external 'shots';
    Splats: integer; external 'splats';
    BonusCurrent: integer; external 'bonusCurrent';
    ShotsCurrent: integer; external 'shotsCurrent';
    SplatsCurrent: integer; external 'splatsCurrent';
  end;

Here's my current workaround:

procedure PXTeamCreate(aTeam: TTeamStruct; aCallback: TPXMessageCallback);
begin
  var aData: Variant := new JObject;
  var aTeamXfer := aTeam.Save;
  asm
    (@aData).team = @aTeamXfer;
  end;
  PXSend(PXM_TEAMCREATE, aData, aCallback);
end;

 

Share this post


Link to post
Share on other sites

I'll try to mimic your example...

type
TTeamXfer = record
    TeamID: integer; external 'teamID';
    Name: string; external 'name';
    Desc: string; external 'desc';
    Web: string; external 'web';
    Bonus: integer; external 'bonus';
    Shots: integer; external 'shots';
    Splats: integer; external 'splats';
    BonusCurrent: integer; external 'bonusCurrent';
    ShotsCurrent: integer; external 'shotsCurrent';
    SplatsCurrent: integer; external 'splatsCurrent';
  end;

type
TTeamStruct = class
  public
    r: TTeamXfer;
    function Save(Value: TTeamXfer): TTeamXfer;
end;

function TTeamStruct.Save(Value: TTeamXfer): TTeamXfer;
begin
  Result.TeamID :=  Value.TeamID;
  Result.Name := Value.Name;
  Result.Desc := Value.Desc;
  Result.Web := Value.Web;
  Result.Bonus := Value.Bonus;
  Result.Shots := Value.Shots;
  Result.Splats := Value.Splats;
  Result.BonusCurrent := Value.BonusCurrent;
  Result.ShotsCurrent := Value.ShotsCurrent;
  Result.SplatsCurrent := Value.SplatsCurrent;
end;

type
  TPXMessageCallback = procedure;

procedure test;
begin
  console.log('testing...');
end;

procedure PXSend(v: integer; aData: Variant; aCallback: TPXMessageCallback);
begin
console.log( aData.obj.r );
end;

procedure PXTeamCreate(aTeam: TTeamStruct; aCallback: TPXMessageCallback);
begin
  var aData: Variant := new JObject;
  aData.obj := aTeam;
  aData.team := @aTeam.Save;
  PXSend(200, aData, @aCallback);
end;

 var
   Team: TTeamStruct;
   Team := TTeamStruct.Create;
   Team.r.TeamID := 10;
   Team.r.Name := 'warleyalex';
   PXTeamCreate(Team, @test);

the compiler emittes this:

function PXTeamCreate(aTeam, aCallback) {
   var aData;
   aData = {};
   aData.obj = aTeam;
   aData.team = $Event1(aTeam,TTeamStruct.Save);
   PXSend(200,aData,aCallback);
};

 

Share this post


Link to post
Share on other sites

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  

×