Ver Mensaje Individual
  #3  
Antiguo 20-03-2013
Avatar de ozsWizzard
ozsWizzard ozsWizzard is offline
Miembro
 
Registrado: may 2004
Ubicación: Murcia
Posts: 190
Reputación: 21
ozsWizzard Va por buen camino
Constantes del formulario

Código Delphi [-]
const
   kCarpeta = 'DATOS';

Función para mostrar el formulario y devolver ruta completa de conexión

Código Delphi [-]
function TForm1.Mostrar(const Ruta: String): String;
var
   i, j: Integer;
   Nom: String;
begin
   ComboBox1.Clear;
   for i := 1 to 100 do
   begin
      Nom := kCarpera + IntTostr(i);
      if FileExists(Ruta + Nom) then
         j := ComboBox1.Items.Add(Nom);
   end;
   //Por defecto se marca la última campaña
   ComboBox1.ItemIndex := j;
   
   ShowModal;
   
   Result := Ruta + kCarpeta + IntToStr(ComboBox1.ItemIndex);

En el archivo ini separaría la ruta del nombre de la base de datos
Código Delphi [-]
path="192.168.1.88:C:\ProyectoMaestro\"
nom= "MAESTRO.IB"

Create del DataModule

Código Delphi [-]
procedure TDataModule1.DataModuleCreate(Sender: TObject);
Var
     Ruta, Nombre, BaseDeDatos: String;
     ElIniFile: TIniFile;
     f: TForm1;
begin
   // Obtiene la ruta y el nombre de la base de datos
   ElIniFile := TIniFile.Create(ExtractFilePath(Application.exename)+'BDatos.ini');
   Ruta := ElIniFile.ReadString('BD','Path','');
   Nombre := ElIniFile.ReadString('BD','Nom','');

   f := TForm1.Create(Self);
   try
      BaseDeDatos := f.Mostrar(Ruta) + '\' + Nombre;
   finally
      f.Free;
   end;
   If BasedeDatos = '' then
      ShowMessage('Error al cargar Base de Datos') 
   else begin
      ibdatabase1.Connected:=false;
      ibdatabase1.DatabaseName:=BasedeDatos;   // BaseGeneral es el TIbDatabase y le asigno la ruta de la base de datos segun .ini
      ibdatabase1.Connected:=true;
   end;
__________________
La Madurez se llama...
~~~Gaia~~~

Última edición por ozsWizzard fecha: 20-03-2013 a las 12:02:10.
Responder Con Cita