Einzelnen Beitrag anzeigen

Monday

Registriert seit: 24. Aug 2012
103 Beiträge
 
FreePascal / Lazarus
 
#6

AW: DosCommand in Konsolenanwendung, identifier not found

  Alt 30. Apr 2017, 09:07
Irgendwie habe ich mir das einfacher vorgestellt:

Programm ruft Anwendung auf, sendet aber nichts an die Anwendung (??) und geht auch nicht auf DosCommand1NewLine . Warum?

In diesem Beispiel erwarte ich jede Menge "111".


Delphi-Quellcode:
program project1;

{$mode delphi}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, CustApp, StrUtils, DosCommand_2009,
  interfaces
  { you can add units after this };

type

  { TMyApplication }

  TMyApplication = class(TCustomApplication)
    DosCommand1: TDosCommand;
    procedure DosCommand1NewLine(Sender: TObject; NewLine: string; OutputType: TOutputType);
  protected
    procedure DoRun; override;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    procedure WriteHelp; virtual;
  end;

{ TMyApplication }



procedure TMyApplication.DosCommand1NewLine(Sender: TObject; NewLine: string; OutputType: TOutputType);
begin
  writeln('1');
end;






procedure TMyApplication.DoRun;
var
  ErrorMsg: String;
  s : string;
  datei: string;
begin
  // quick check parameters
  ErrorMsg:=CheckOptions('h','help');
  if ErrorMsg<>'then begin
    ShowException(Exception.Create(ErrorMsg));
    Terminate;
    Exit;
  end;

  // parse parameters
  if HasOption('h','help') then begin
    WriteHelp;
    Terminate;
    Exit;
  end;

    { add your program here }

    DosCommand1 := TDoscommand.Create(self);
    DosCommand1.OnNewLine := DosCommand1NewLine; //???

    datei := 'cmd';
    DosCommand1.CommandLine := datei;
    DosCommand1.Execute;
    DosCommand1.SendLine('dir',True);

   read(s);

  // stop program loop
  Terminate;
end;

constructor TMyApplication.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException:=True;
end;

destructor TMyApplication.Destroy;
begin
  inherited Destroy;
end;

procedure TMyApplication.WriteHelp;
begin
  { add your help code here }
  writeln('Usage: ',ExeName,' -h');
end;

var
  Application: TMyApplication;

begin
  Application:=TMyApplication.Create(nil);
  Application.Title:='My Application';
  Application.Run;
  Application.Free;
end.
  Mit Zitat antworten Zitat