Einzelnen Beitrag anzeigen

schöni

Registriert seit: 23. Jan 2005
Ort: Dresden
445 Beiträge
 
Delphi 7 Personal
 
#1

Oberfläche für Freeware Kommandozeilen-Programm Unix2Dos

  Alt 16. Mai 2005, 22:58
Hallo Delphianer!

Ich habe mal wieder ein Problem. Ich will eine .EXE Datei aufrufen, konkret die
Datei Unix2Dos.exe, um Pascal-Quelltexte aus der Unix Welt in das DOS/Windows
Format zu konvertieren.

Unix: Zeile schließt mit $0A ab
Dos/Windows: Zeile schließt mit $0D0A ab

Ich will nun eine Oberfläche bauen, die mir in einer Listbox die zu
konvertierenden Dateien anbietet. Dann wähle ich eine aus (später
auch mehrere), die dann der Reihe nach konvertiert werden sollen.

Mein Problem ist: Die Konvertierung klappt nicht. Warum?

Von der Kommandozeile aus klappt die Konvertierung einwandfrei. Nur nicht, wenn ich das Tool
von meiner Delphi-Anwendung aus aufrufe.

Hier die Unit mit der Startroutine, die Unix2Dos aufruft:
Delphi-Quellcode:
unit Execute;

interface

uses Windows, Messages, SysUtils, Classes;

type
  TCommandLine = type String;

function ProcessExecute(CommandLine: TCommandLine; cShow: word): Integer;
function ExecProcess(CommandLine,DirOfProc: TCommandLine; cShow: word): Integer;

implementation

uses ShellAPI;

function ProcessExecute(CommandLine: TCommandLine; cShow: word): Integer;
var
  Rslt: LongBool;
  StartUpInfo: TStartUpInfo;
  ProcessInfo: TProcessInformation;
  hProcess,hThread: THandle;
begin
   FillChar(StartUpInfo, SizeOf(TStartUpInfo), 0);

   with StartUpInfo do
   begin
      cb := SizeOf(TStartUpInfo);
      dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
      wShowWindow := cShow;
   end;

   Rslt := CreateProcess(
     PChar(CommandLine),
     nil,
     nil,
     nil,
     false,
     NORMAL_PRIORITY_CLASS,
     nil, //Environment
     nil, //aktuelles Verzeichnis
     StartUpInfo,
     ProcessInfo
   );

   if Rslt then
   begin
      WaitForInputIdle(hProcess, INFINITE);
      CloseHandle(hThread);
      CloseHandle(hProcess);
      Result := 0;
   end
   else Result := GetLastError;
end;

function ExecProcess(CommandLine,DirOfProc: TCommandLine; cShow: word): Integer;
var
  Rslt: LongBool;
  StartUpInfo: TStartUpInfo;
  ProcessInfo: TProcessInformation;
  hProcess,hThread: THandle;
begin
   FillChar(StartUpInfo, SizeOf(TStartUpInfo), 0);

   with StartUpInfo do
   begin
      cb := SizeOf(TStartUpInfo);
      dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
      wShowWindow := cShow;
   end;

   Rslt := CreateProcess(
     PChar(CommandLine),
     nil,
     nil,
     nil,
     false,
     NORMAL_PRIORITY_CLASS,
     nil, //Environment
     PChar(DirOfProc), //aktuelles Verzeichnis
     StartUpInfo,
     ProcessInfo
   );

   if Rslt then
   begin
      WaitForInputIdle(hProcess, INFINITE);
      CloseHandle(hThread);
      CloseHandle(hProcess);
      Result := 0;
   end
   else Result := GetLastError;
end;

end.
Und hier das Hauptprogramm:

Delphi-Quellcode:
unit ConvMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  FileCtrl, StdCtrls, Execute;

type
  TForm1 = class(TForm)
    btnUnixToDos: TButton;
    btnDosUnix: TButton;
    FileListBox1: TFileListBox;
    DirectoryListBox1: TDirectoryListBox;
    procedure btnUnixToDosClick(Sender: TObject);
    procedure btnDosUnixClick(Sender: TObject);
  private
    { Private-Deklarationen }
    NewInstance: THandle;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.btnUnixToDosClick(Sender: TObject);
var toConvert: String; CurrentDir, Action: String;
begin
   //Konvertierung des Zeilenendezeichens von UNIX nach DOS CRLF
   CurrentDir := GetCurrentDir;
   if CurrentDir[Length(CurrentDir)]<>'\then CurrentDir := CurrentDir + '\';
   Action := CurrentDir + 'Unix2Dos.exe ';
   SetLength(CurrentDir, Length(CurrentDir)-1);
   toConvert := FileListBox1.Items[FileListBox1.ItemIndex];
   //ShellExecInfo.lpParameters := FileListBox1.Items[FileListBox1.ItemIndex]
   ExecProcess(
     Action + toConvert,
     GetCurrentDir,
     SW_SHOWNORMAL
   );
end;

procedure TForm1.btnDosUnixClick(Sender: TObject);
begin
   //Konvertierung des Zeilenendezeichens von DOS nach UNIX LF
   ShowMessage('Diese Umwandlung konnte noch nicht implenentieirt werden! Leider');
end;

end.
Danke schon mal für Eure Hilfe

schöni
Damit der Topf nicht explodiert, lässt man es ab und zu mal zischen.
  Mit Zitat antworten Zitat