From the 2009 release of Delphi (if I'm not mistaken) came the namespaces . I would like to know, in a simple example if possible that illustrates a case of advantage, what would be the advantages of namespaces in Delphi?
Accounts.cs file :
namespace Projeto.Forms {
public class ContasForm : Form {
...
}
}
Archive Shopping.cs :
namespace Projeto.Forms {
public class ComprasForm : Form {
...
}
}
Client.cs file :
namespace Projeto.Forms {
public class ClienteForm : Form {
...
}
}
In a fourth file, MainForm.cs , I would have access to all three classes only by references namespace
:
using Projeto.Forms;
namespace Projeto {
public class ContasForm : Form {
private ContasForm contasForm;
private ComprasForm comprasForm;
private ClienteForm clienteForm;
}
}
In Delphi this does not happen:
File Project.Forms.Accounts.pas :
unit Projeto.Forms.Contas;
interface
uses ...
type
TContasForm = class(Form)
...
File Project.Forms.Compras.pas :
unit Projeto.Forms.Compras;
interface
uses ...
type
TComprasForm = class(Form)
...
File Project.Forms.Customer.pas :
unit Projeto.Forms.Cliente;
interface
uses ...
type
TClienteForm = class(Form)
...
Finally, when you want to refer to them in Project.Forms.MainForm , do the following:
unit Projeto.Forms.MainForm;
interface
uses Projeto.Forms.Contas, Projeto.Forms.Compras, Projeto.Forms.Cliente;
type
TMainForm = class(Form)
...
No you can do something like Projeto.Forms
and from there you have access to all three classes. Much less is allowed in Delphi to have more than one file with the same name.
The only way I saw of having such a benefit would be to manipulate . Example:
Create a unit with the name Project.Forms.pas :
unit Projeto.Forms;
interface
type
TContasForm = Projeto.Forms.Contas.TContasForm;
TComprasForm = Projeto.Forms.Compras.TComprasForm;
TClienteForm = Projeto.Forms.Cliente.TClienteForm;
...
And then make the reference as you had quoted, uses Projeto.Forms;
and then have access to the three classes.
Well, I do not know if this would have consequences and, of course, it was just to illustrate.
So, I ask: What are the advantages of using namespaces in Delphi?
I ask for a small example just to illustrate. Thanks!