Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Agregar Parametro a Create (https://www.clubdelphi.com/foros/showthread.php?t=59051)

totote 11-08-2008 13:50:22

Agregar Parametro a Create
 
Buenas gente, cómo puedo hacer para agregar un parametro a un constructor, la idea es, yo tengo varios formularios en el cual se le asigna un código, lo que quiero hacer es que cuando creo el formulario a parte del parametro de siempre :P le pase un número que va a ser el código que le asigno, lo que habia hecho era esto:

Código Delphi [-]
type
  TfrmBase = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    Cod: Integer;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent; ID: Integer); override;
  end;

constructor TfrmBase.Create(AOwner: TComponent; ID: Integer);
begin
  inherited;
  Cod:= ID;
end;

Pero me da el error :
Declaration of 'Create' differs from previous declaration

Agradeceria cualquier tipo de ayuda.

Saludos :D

totote 11-08-2008 14:05:36

Bueno chusmeando un poco de código de delphi encontre la solucion, en ves de modificar el create, creo otro constructor y el código sería así:

Código Delphi [-]
type
  TfrmBase = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    Cod: Integer;
  public
    { Public declarations }
    constructor CreateNew(AOwner: TComponent; ID: Integer); virtual;
  end;

constructor TfrmBase.CreateNew(AOwner: TComponent; ID: Integer);
begin
  inherited Create(AOwner);
  Cod:= ID;
end;

De esa manera me funcionó.

Saludos :D

coso 11-08-2008 14:08:08

si haces override, lo que estas es 'reescribiendo' una funcion anterior, por lo que la nueva función debe tener la misma estructura. Prueba de poner 'overload', creando asi dos tipos de constructores (uno sin id, el otro con) (no podras usar el inherited, tendras que usar Create(AOwner))

coso 11-08-2008 14:13:22

Veo q te adelantaste :rolleyes: . Lo más correcto, igualmente, es el 'overload' :p te dejo la ayuda de delphi

Cita:

A method can be redeclared using the overload directive. In this case, if the redeclared method has a different parameter signature from its ancestor, it overloads the inherited method without hiding it. Calling the method in a descendant class activates whichever implementation matches the parameters in the call.
If you overload a virtual method, use the reintroduce directive when you redeclare it in descendant classes. For example,


totote 11-08-2008 14:22:24

Grax coso por la data :D y te consulto de donde sacaste la info para tenerla de referencia para la proxima jeje.

Saludos y nuevamente Grax

coso 11-08-2008 14:23:53

X) pues de la OOP, aunque ahora hay tantas palabrejas (estaba leyendo lo de virtual y reintroduce) que ya uno se pierde :confused: La cita es de la ayuda del Delphi :)


La franja horaria es GMT +2. Ahora son las 02:19:04.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi