unit uViewDireccionEntrega; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewBase, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxTextEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, uDADataTable, Grids, DBGrids, ActnList, ImgList, PngImageList, ComCtrls, ToolWin, cxGridDBTableView, uViewDetallesGenerico, cxCurrencyEdit, uDAInterfaces, cxLookAndFeels, cxLookAndFeelPainters, dxLayoutControl, StdCtrls, Mask, DBCtrls, cxContainer, dxLayoutcxEditAdapters, cxDBEdit, cxMaskEdit, cxDropDownEdit; type TfrViewDireccionEntrega = class(TfrViewBase) dxLayoutControl1Group_Root: TdxLayoutGroup; dxLayoutControl1: TdxLayoutControl; dsDetalles: TDADataSource; dxLayoutControl1Item2: TdxLayoutItem; cbPoblacion: TcxDBComboBox; dxLayoutControl1Item3: TdxLayoutItem; cbProvincia: TcxDBComboBox; dxLayoutControl1Item4: TdxLayoutItem; eCalle: TcxDBTextEdit; dxLayoutControl1Item5: TdxLayoutItem; eCodigoPostal: TcxDBTextEdit; dxLayoutControl1Group1: TdxLayoutGroup; procedure cbPoblacionPropertiesInitPopup(Sender: TObject); procedure cbProvinciaPropertiesInitPopup(Sender: TObject); protected FProvincias : TStringList; FIDProvincia : Integer; //Almacenará la provincia que hay seleccionada para no cargar las poblaciones si no es necesario FPoblaciones : TStringList; procedure CargarProvincias; procedure CargarPoblaciones; public constructor Create(AOwner : TComponent); override; destructor Destroy; override; end; implementation {$R *.dfm} uses uProvinciasPoblacionesController, uStringsUtils; { TfrViewDireccionEntrega } procedure TfrViewDireccionEntrega.CargarPoblaciones; var i : integer; begin if (FIDProvincia <> StrToInt(FProvincias.Values[cbProvincia.Text])) then Begin FIDProvincia := StrToInt(FProvincias.Values[cbProvincia.Text]); with TProvinciasPoblacionesController.Create do try FPoblaciones := DarListaPoblaciones(FIDProvincia); with cbPoblacion.Properties.Items do begin BeginUpdate; try Clear; for i := 0 to FPoblaciones.Count - 1 do Add(FPoblaciones.Names[i]); finally EndUpdate; end; end; finally Free; end; End; end; procedure TfrViewDireccionEntrega.CargarProvincias; var i : integer; begin with TProvinciasPoblacionesController.Create do try FProvincias := DarListaProvincias; with cbProvincia.Properties.Items do begin BeginUpdate; try Clear; for i := 0 to FProvincias.Count - 1 do Add(FProvincias.Names[i]); finally EndUpdate; end; end; finally Free; end; end; procedure TfrViewDireccionEntrega.cbPoblacionPropertiesInitPopup(Sender: TObject); begin inherited; ShowHourglassCursor; try FreeANDNIL(FPoblaciones); if not Assigned(FProvincias) then CargarProvincias; if not EsCadenaVacia(cbProvincia.Text) and (FProvincias.IndexOfName(cbProvincia.Text) <> -1) then CargarPoblaciones finally HideHourglassCursor; end; end; procedure TfrViewDireccionEntrega.cbProvinciaPropertiesInitPopup(Sender: TObject); begin inherited; ShowHourglassCursor; try if not Assigned(FProvincias) then CargarProvincias; finally HideHourglassCursor; end; end; constructor TfrViewDireccionEntrega.Create(AOwner: TComponent); begin inherited; FIDProvincia := 0; FProvincias := NIL; FPoblaciones := NIL; end; destructor TfrViewDireccionEntrega.Destroy; begin if Assigned(FProvincias) then FreeANDNIL(FProvincias); if Assigned(FPoblaciones) then FreeANDNIL(FPoblaciones); inherited; end; end.