class in class within different units

Hi,

I would like to build a class called TUser in a unit called unTUser.pas
inside TUser will have a variable that will be a class TConfigs

[code]
Type
TUser = Class
Private
stName :String;
stLogin :String;
stPassword :String;
Published

teste: TConfigs;
End;
[/code]

i guess this is ok, i only have to create unTConfigs, the class and add unTConfigs to the uses clause of unTUser, right?
but If I want to have a pointer to the owner of the configs inside the config class?
or, have other users inside the config class...
i guess i will have a circular reference?
how do I avoid that?
because I want to organize my stuff, i know i could put the two classes in the same file, but i normally make one file to each class...

can you help me please?
how can I do this the way I want to?
2 units, 2 classes, they can see and use each other ?
is this that bad that delphi doesn't want me to?

Thank you!
Jonathan

Comments

  • : Hi,
    :
    : I would like to build a class called TUser in a unit called
    : unTUser.pas
    : inside TUser will have a variable that will be a class TConfigs
    :
    : [code]:
    : Type
    : TUser = Class
    : Private
    : stName :String;
    : stLogin :String;
    : stPassword :String;
    : Published
    :
    : teste: TConfigs;
    : End;
    : [/code]:
    :
    : i guess this is ok, i only have to create unTConfigs, the class and
    : add unTConfigs to the uses clause of unTUser, right?
    : but If I want to have a pointer to the owner of the configs inside
    : the config class?
    : or, have other users inside the config class...
    : i guess i will have a circular reference?
    : how do I avoid that?
    : because I want to organize my stuff, i know i could put the two
    : classes in the same file, but i normally make one file to each
    : class...
    :
    : can you help me please?
    : how can I do this the way I want to?
    : 2 units, 2 classes, they can see and use each other ?
    : is this that bad that delphi doesn't want me to?
    :
    : Thank you!
    : Jonathan
    You can do that if one unit uses the other in the interface part, while the other unit uses the on ein the implementation:
    [code]
    unit Unit1;

    interface

    uses
    Unit2;

    type
    TUser = class
    config: TConfig;
    end;

    implementation

    end.
    [/code]

    [code]
    unit Unit2;

    interface

    type
    TConfig = class
    Parent: TObject;
    end;

    implementation

    uses
    Unit1;

    function TConfig.getParent: TUser;
    begin
    result := TUser(parent);
    end;

    end.
    [/code]
  • Thank you
    : : Hi,
    : :
    : : I would like to build a class called TUser in a unit called
    : : unTUser.pas
    : : inside TUser will have a variable that will be a class TConfigs
    : :
    : : [code]: :
    : : Type
    : : TUser = Class
    : : Private
    : : stName :String;
    : : stLogin :String;
    : : stPassword :String;
    : : Published
    : :
    : : teste: TConfigs;
    : : End;
    : : [/code]: :
    : :
    : : i guess this is ok, i only have to create unTConfigs, the class and
    : : add unTConfigs to the uses clause of unTUser, right?
    : : but If I want to have a pointer to the owner of the configs inside
    : : the config class?
    : : or, have other users inside the config class...
    : : i guess i will have a circular reference?
    : : how do I avoid that?
    : : because I want to organize my stuff, i know i could put the two
    : : classes in the same file, but i normally make one file to each
    : : class...
    : :
    : : can you help me please?
    : : how can I do this the way I want to?
    : : 2 units, 2 classes, they can see and use each other ?
    : : is this that bad that delphi doesn't want me to?
    : :
    : : Thank you!
    : : Jonathan
    : You can do that if one unit uses the other in the interface part,
    : while the other unit uses the on ein the implementation:
    : [code]:
    : unit Unit1;
    :
    : interface
    :
    : uses
    : Unit2;
    :
    : type
    : TUser = class
    : config: TConfig;
    : end;
    :
    : implementation
    :
    : end.
    : [/code]:
    :
    : [code]:
    : unit Unit2;
    :
    : interface
    :
    : type
    : TConfig = class
    : Parent: TObject;
    : end;
    :
    : implementation
    :
    : uses
    : Unit1;
    :
    : function TConfig.getParent: TUser;
    : begin
    : result := TUser(parent);
    : end;
    :
    : end.
    : [/code]:
    :
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories