#1 2015-11-18 20:26:45

ioda19
Member
Registered: 2015-11-18
Posts: 14

Need help (Not for mORMot Framework but maby someone can help me)

Hi,

I know this question is not about mORMot Framework but on this forum some programmer are expert and maybe can help me.

I have this structure in C#

public class User
{
  ...
  public ICollection<UserGroup> Groups { get; set; }
  ...
}


public class UserGroup
{
  ...
  public User User { get; set; }
  ...
}

As you can see, User is in UserGroup and UserGroup is in User
In C# you can this


But I need to use same structure in Delphi 6 but I have circular reference between two unit (User and UserGroup)
Someone have a suggestion because I need to serialize and deserialize JSON from C# to Delphi and vice-versa

Thank you

Offline

#2 2015-11-19 09:27:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Need help (Not for mORMot Framework but maby someone can help me)

Create a single unit with both classes, then define your class as forward.

type
  TUserGroup = class; // forward declaration
  TUser = class
  ...
     here you can use TUserGroup

  TUserGroup = class // real TUserGroup definition
  ...

In C# and Java, you are used to define one source code file per class.
In Delphi, it is not wanted, nor possible, since the on-pass compiler avoid circular references, and therefore the solution is to define all circular references classes in a single unit.

Offline

Board footer

Powered by FluxBB