luisgutierrezb@gmail.com Guest
|
Posted: Sat Jul 23, 2005 2:11 pm Post subject: pointer problem |
|
|
Hi, everyone.
excuse my english...
i try this:
type
PunteroDatos = ^Datos;
Datos = Record
Dato:String;
Anterior: PunteroDatos;
Siguiente: PunteroDatos;
End;
Type
TLista = Class(TObject)
Private
Primero, Ultimo, Actual, ArregloDatos: PunteroDatos; // first,
last, actual position
Function AgregaElemento(Elemento: PunteroDatos):Boolean; //add new
element
Public
Function AgregaDatos(Dato1: String): Boolean; //add new element
...
...
end;
Function TLista.AgregaDatos(Dato1: String): Boolean;
Begin
New(ArregloDatos); <---- here! raise a exception
ArregloDatos^.Dato := Dato1;
Result := AgregaElemento(ArregloDatos);
End;
the question is why¿? raise a exception
but, if i delete "ArregloDatos" and declare this in fuction:
Function TLista.AgregaDatos(Dato1: String): Boolean;
Var
ArregloDatos: PunteroDatos;
Begin
New(ArregloDatos);
ArregloDatos^.Dato := Dato1;
Result := AgregaElemento(ArregloDatos);
End;
then, works fine...
|
|