que tiempos aquellos de Turbo Vision...
El problema no está en el código que has mostrado en si....
Creo que debes revisar cómo manejas la memoria... pues por allí encontraras seguramente algun bug...
Para ilustrarlo, he hecho este ejemplo, totalmente inutil... pero que compila y funciona perfectamente...
Primero crea un unit, y pegá el siguiente código:
Código:
unit Unit2;
interface
Type
TJachElem = Class
private
a : Integer;
b : Integer;
function GetaValue: Integer;
function GetbValue: Integer;
public
Constructor Create(aa, ab: Integer);
Destructor Destroy; override;
Property aValue : Integer read GetaValue;
Property bValue : Integer read GetbValue;
end;
TJachTable = Class
private
Elem1 : TJachElem;
Elem2 : TJachElem;
function GetElem1a: Integer;
function GetElem1b: Integer;
function GetElem2a: Integer;
function GetElem2b: Integer;
public
Constructor Create;
Destructor Destroy; override;
Function AddElem1(aElem : TJachElem) : TJachTable;
Function AddElem2(aElem : TJachElem) : TJachTable;
Property Elem1a : Integer read GetElem1a;
Property Elem1b : Integer read GetElem1b;
Property Elem2a : Integer read GetElem2a;
Property Elem2b : Integer read GetElem2b;
end;
implementation
uses SysUtils;
{ tJachElem }
constructor tJachElem.Create(aa, ab: Integer);
begin
inherited create;
a := aa;
b := ab;
end;
destructor tJachElem.Destroy;
begin
inherited;
end;
function TJachElem.GetaValue: Integer;
begin
Result := a;
end;
function TJachElem.GetbValue: Integer;
begin
Result := b;
end;
{ tJachTable }
function TJachTable.AddElem1(aElem: TJachElem): TJachTable;
begin
if assigned(Elem1) Then
Elem1.Free;
Elem1 := aElem;
Result := Self;
end;
function TJachTable.AddElem2(aElem: TJachElem): TJachTable;
begin
if assigned(Elem2) Then
Elem2.Free;
Elem2 := aElem;
Result := Self;
end;
constructor tJachTable.Create;
begin
inherited;
end;
destructor tJachTable.Destroy;
begin
if Assigned(Elem1) Then
Elem1.Free;
if assigned(Elem2) Then
Elem2.Free;
inherited;
end;
function TJachTable.GetElem1a: Integer;
begin
if not Assigned(Elem1) Then
raise Exception.Create('No se ha asignado Elem1!');
Result := Elem1.aValue;
end;
function TJachTable.GetElem1b: Integer;
begin
if not Assigned(Elem1) Then
raise Exception.Create('No se ha asignado Elem1!');
Result := Elem1.bValue;
end;
function TJachTable.GetElem2a: Integer;
begin
if not Assigned(Elem2) Then
raise Exception.Create('No se ha asignado Elem2!');
Result := Elem2.aValue;
end;
function TJachTable.GetElem2b: Integer;
begin
if not Assigned(Elem2) Then
raise Exception.Create('No se ha asignado Elem2!');
Result := Elem2.bValue;
end;
end.
Luego en otro unit podes hacer esta llamada:
Código:
Var
FTabla : TJachTable;
Begin
FTabla := TJachTable.Create.AddElem1(TJachElem.Create(1, 2)).AddElem2(TJachElem.Create(2, 1));
try
Label1.Caption := IntToStr(FTabla.Elem1a);
Label2.Caption := IntToStr(FTabla.Elem1b);
Label3.Caption := IntToStr(FTabla.Elem2a);
Label4.Caption := IntToStr(FTabla.Elem2b);
finally
FTabla.Free;
end;
End;
y todo funciona perfectamente.
Hasta luego.
![Wink](http://www.clubdelphi.com/foros/images/smilies/wink.gif)