FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
Problema con Clase creada dentro de otra.
Hola
Cree una clase que maneja la estructura de categorias y subcategorias. Cada categoria tiene asociadas ciertas propiedades (Nombre, ID, Indice de Icono, Campos, etc) y ademas un Arreglo de SubCategorias. Cada SubCategoria tiene ciertas propiedades (Nombre, IndiceIcono, Categoria a la que pertenece, etc) Y la clase que controla todo se llama TEstructuraCategorias y tiene un ADOConnection y un arreglo de Categorias. Tiene un ADOConnection por que con este hace una consulta a una BD y saca toda la estructura de las categorias. Mi problema es el siguiente. Tengo definidas las 3 clases: Código:
type TSubcategoria = class private cIDSubCategoria: Integer; cIDCategoria: Integer; cNombreSubCategoria: String; cIndiceIcono: Integer; public property IDSubCategoria: Integer read cIDSubCategoria write cIDSubCategoria; property IDCategoria: Integer read cIDCategoria write cIDCategoria; property NombreSubCategoria: String read cNombreSubCategoria write cNombreSubCategoria; property IndiceIcono: Integer read cIndiceIcono write cIndiceIcono; constructor Crear(aIDSubCategoria: Integer; aIDCategoria: Integer; aNombreSubCategoria: String; aIndiceIcono: Integer); end; type TStrings = Array of String; TSubCategorias = Array of TSubCategoria; TCategoria = class private cIDCategoria: Integer; cNombreCategoria: String; cIndiceIcono: Integer; cPrefijo: String; cNombreCampos: TStrings; cCantidadCampos: Integer; cSubCategorias: TSubCategorias; public property IDCategoria: Integer read cIDCategoria write cIDCategoria; property NombreCategoria: String read cNombreCategoria write cNombreCategoria; property IndiceIcono: Integer read cIndiceIcono write cIndiceIcono; property Prefijo: String read cPrefijo write cPrefijo; property NombreCampos: TStrings read cNombreCampos write cNombreCampos; property CantidadCampos: Integer read cCantidadCampos write cCantidadCampos; property SubCategorias: TSubCategorias read cSubCategorias write cSubCategorias; constructor Crear(aIDCategoria: Integer; aNombreCategoria: String; aIndiceIcono: Integer; aPrefijo: String; aCampo1: String; aCampo2: String; aCampo3: String; aCampo4: String; aCampo5: String; aCampo6: String; aCampo7: String; aCampo8: String; aCampo9: String; aCampo10: String); procedure AgregarSubCategoria(aIDSubCategoria: Integer; aNombreSubCategoria: String; aIndiceIcono: Integer); end; type TCategorias = Array of TCategoria; TEstructuraCategorias = class private cConnection: TADOConnection; cCategorias: TCategorias; public property Categorias: TCategorias read cCategorias write cCategorias; constructor Crear(aConnection: TADOConnection); procedure Actualizar; end; Código:
constructor TEstructuraCategorias.Crear(aConnection: TADOConnection); begin cConnection:=aConnection; Actualizar; end; procedure TEstructuraCategorias.Actualizar; var i, j: integer; Categoria: TCategoria; Query, Query1: TADOQuery; begin Query:=TADOQuery.Create(nil); Query.Connection:=cConnection; Query1:=TADOQuery.Create(nil); Query1.Connection:=cConnection; Query.Close; Query.SQL.Text:='SELECT * FROM Categorias ORDER BY Nombre'; Query.Open; For i:=0 to Query.RecordCount-1 do begin Categoria:=TCategoria.Crear(Query.Fields[0].AsInteger, Query.Fields[1].AsString, Query.Fields[2].AsInteger, Query.Fields[3].AsString, Query.Fields[4].AsString, Query.Fields[5].AsString, Query.Fields[6].AsString, Query.Fields[7].AsString, Query.Fields[8].AsString, Query.Fields[9].AsString, Query.Fields[10].AsString, Query.Fields[11].AsString, Query.Fields[12].AsString, Query.Fields[13].AsString); Query1.Close; Query1.SQL.Text:='SELECT * FROM SubCategorias ORDER BY Nombre WHERE IDCategoria='+Query.Fields[1].AsString; Query1.Open; For j:=0 to Query1.RecordCount do begin Categoria.AgregarSubCategoria(Query1.Fields[0].AsInteger, Query1.Fields[2].AsString, Query1.Fields[3].AsInteger); Query1.Next; end; SetLength(cCategorias, High(cCategorias)+2); cCategorias[High(cCategorias)]:=Categoria; Query.Next; end; Query.Close; Query.Free; Query1.Close; Query1.Free; end; Pero cuando lo ejecuto me dice EAccessViolation al crear una Categoria. O sea, cuando pongo Break, me marca esta linea: Código:
Categoria:=TCategoria.Crear(Query.Fields[0].AsInteger, Query.Fields[1].AsString, Query.Fields[2].AsInteger, Query.Fields[3].AsString, Query.Fields[4].AsString, Query.Fields[5].AsString, Query.Fields[6].AsString, Query.Fields[7].AsString, Query.Fields[8].AsString, Query.Fields[9].AsString, Query.Fields[10].AsString, Query.Fields[11].AsString, Query.Fields[12].AsString, Query.Fields[13].AsString); Cita:
Gracias por su tiempo. Saludos. Última edición por Holderhek fecha: 03-02-2005 a las 22:07:28. |
|
|
|