Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   Ejecutar Archivo (https://www.clubdelphi.com/foros/showthread.php?t=39562)

Diego9 24-01-2007 02:32:21

Ejecutar Archivo
 
Buenas Noches

Para ejecutar un archivo utilizo

Código Delphi [-]
ShellExecute(MiForm.Handle,nil,('c:\Miarchivo.extension'),'','',SW_Shownormal);

Pero si este archivo no siempre va a ser el mismo y voy a coger la ruta y el archivo de un cuadro de dialogo, ¿como puedo hacerlo?.

Gracias

dec 24-01-2007 02:41:23

Hola,

Siempre puedes utilizar variables:

Código Delphi [-]
var
  rutaArchivo: string;
begin
  rutaArchivo := 'C:\unarchivo.txt';
  ShellExecute(MiForm.Handle, 'open', PChar(rutaArchivo),nil,nil,SW_SHOWNORMAL);
end;

Ahora tienes que investigar sobre el uso de un "TOpenDialog", pero, en definitiva, ya sabes que puedes guardar la elección del usuario en la variable "rutaArchivo", por ponerte un ejemplo, de modo que luego puedas usarla en la función "ShellExecute".

Una posible forma de hacerlo:

Código Delphi [-]
begin
  with TOpenDialog.Create(Self) do
  begin
    if Execute then
    begin
      ShellExecute(Self.Handle, 'open', PChar(FileName), nil, nil, SW_SHOWNORMAL);
    end;
    Free;
  end;

Otra posible forma:

Código Delphi [-]
var
  dlg: TOpenDialog;
begin
  dlg := TOpenDialog.Create(Self);
  try
    if dlg.Execute then
      ShellExecute(Self.Handle, 'open',
       PChar(dlg.FileName), nil, nil, SW_SHOWNORMAL);
  finally
    dlg.Free;
  end;
end;

Y aún otra más:

Código Delphi [-]
begin
  if OpenDialog1.Execute then
  begin
    ShellExecute(Self.Handle, 'open',
      PChar(OpenDialog1.FileName), nil, nil, SW_SHOWNORMAL);
  end;
end;

Diego9 24-01-2007 02:47:43

Gracias David me has alegrado la noche, funciona correctamente.
Saludos,


La franja horaria es GMT +2. Ahora son las 15:36:53.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi