Ver Mensaje Individual
  #4  
Antiguo 29-12-2017
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.732
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Código Delphi [-]
procedure RellenaCuentas;
var
  Nodo : TTreeNode;
begin
  // Nodo primer nivel
  Nodo := TreeViewCuentas.Items.Add(nil, 'Cuentas');
  RellenaCuentasNivel(Nodo);
end;

procedure RellenaCuentasNivel(Nodo: TTreeNode; Nivel: integer = 1);
var
  aNodo : TTreeNode;
  Codigo, Cuenta : string;
begin
  /// Recorro cuentas del [Nivel] y las agrego al [Nodo].
  
  // Creo ADOQuery de Cuentas del nivel
  with ADOQuery.Create(nil) do
  begin
    try
      // Filtrar cuentas del nivel
      // SELECT CODIGO, CUENTA FROM CUENTAS WHERE NIVEL = :NIVEL ORDER BY CODIGO

      // Recorro las cuentas
      while not EOF do
      begin
        Codigo := FieldByName['CODIGO'].AsString;
        Cuenta := FieldByName['CUENTA'].AsString];
        aNodo := TreeViewCuentas.Items.AddChild(Nodo, Codigo + ' ' + Cuenta);

        // Llamada recursiva para el siguiente nivel
        RellenaCuentas(aNodo, Nivel + 1);

        Next;
      end;
      Close;
    finally
      Free;
    end;
  end;
end;
Responder Con Cita