Ver Mensaje Individual
  #5  
Antiguo 09-05-2006
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.141
Reputación: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Una traducción del código que copiaste, pensando en derivar la clase de "TComponent" para hacer uso de lo que dice el compañero Walter, podría ser como sigue en Delphi:

Código Delphi [-]
unit UEcuaciones;

interface

uses
  Classes;

type
  TEcuaciones = class(TComponent)
  private
    FNombre, FApellido: string;
  public
    constructor Create(AOwner: TComponent); override;
    function GetNombre : string;
    function GetApellido : string;
    procedure SetNombre(nombre: string);
    procedure SetApellido(apellido: string);
  end;

implementation

{ TEcuaciones }

constructor TEcuaciones.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  { TODO }
end;

function TEcuaciones.GetNombre: string;
begin
  Result := Self.FNombre;
end;

function TEcuaciones.GetApellido: string;
begin
  Result := Self.FApellido;
end;

procedure TEcuaciones.SetNombre(nombre: string);
begin
  if (Self.FNombre <> nombre) then
    Self.FNombre := nombre;
end;

procedure TEcuaciones.SetApellido(apellido: string);
begin
  if (Self.FApellido <> apellido) then
    Self.FApellido := apellido;
end;

end.

Sin embargo, fíjate que los métodos "Gets" y "Sets" no hacen sino asignar un nuevo valor a las variables que nos interesan, por un lado, y por otro devolver el valor de dichas variables. Entonces podríamos simplicar un poco el código en Delphi, gracias a las "propiedades":

Código Delphi [-]
unit UEcuaciones2;

interface

uses
  Classes;

type
  TEcuaciones = class(TComponent)
  private
    FNombre, FApellido: string;
  public
    constructor Create(AOwner: TComponent); override;
    property Nombre: string read FNombre write FNombre;
    property Apellido: string read FApellido write FApellido;
  end;

implementation

{ TEcuaciones }

constructor TEcuaciones.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  { TODO }
end;

end.
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita