Autor Beitrag
Moonbiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 08.12.06 23:08 
Hi, schön wieder hier zu sein.

Ich möchte eine Anwendung per Startparamter steuern (später über geplante tasks...), nur werden übergebene Parameter zwar richtig eingelesen, nur reagiert mein Programm nicht drauf, und ich hoffe ihr weist mich auf einen sicher schnell zu finden aber von mir scheinbar immerwieder übersehehen Fehler hin, damits weiter gehen kann.

Hier nun das program:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
program KleBu;

uses
  Forms,
  Classes,
  main in 'main.pas' {MainForm};

{$R *.res}
const
  //Titel des Programmes (Task)
  AppTitle='KleBu';

var
  i:integer;
  StartParam:TStringList;

begin
  StartParam:=TStringList.Create;
  StartParam.Add('1');

  if paramcount > 0 then
    for i:=0 to paramcount do
      StartParam.Add(paramstr(i));

//Testparameter
  StartParam.Add('log');
  StartParam.Add('logfile');
  StartParam.Add('hier steht der pfad');
//Ende Testparameter

  Application.Initialize;
  Application.Title := AppTitle;
  Application.CreateForm(TMainForm, MainForm);
  MainForm.SetStartParam(StartParam);
  Application.Run;
end.


und die main Unit:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
unit main;

interface

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

type
  TMainForm = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure SetStartParam(tmpStartParam: TStringList);
    procedure Memo1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  MainForm: TMainForm;
  StartParam: TStringList;  //StringListe der übergebenen Startparameter
  writeLog: Boolean;  //Schalter zum Schreiben einer Log-Datei
  logFile, ApplicationPath: String;

const
  //Beschreibung der Titelleiste der Form
  AppCap='kleines-helferlein Backup';

  lpt1=888;
  ERR1='Fehler (io.dll): Treiber nicht installiert - es konnte auf den Port nicht geschrieben werden!';

  procedure PortOut(Port : Word; Data : Byte); stdcall; external 'io.dll';
  function PortIn(Port : Word):Byte; stdcall; external 'io.dll';
  function IsDriverInstalled : Boolean;  external 'io.dll';

implementation

{$R *.dfm}

//if IsDriverInstalled then PortOut(lpt1,1) else Showmessage(ERR1);

procedure TMainForm.FormCreate(Sender: TObject);
begin
  MainForm.Caption:=AppCap;
  StartParam:=TStringList.Create;
  GetDir(0, ApplicationPath);
  if IsDriverInstalled then PortOut(lpt1,0) else Showmessage(ERR1);
end;

procedure TMainForm.Memo1Click(Sender: TObject);
var
  i: integer;
begin
  with memo1.Lines do
    begin
      clear;
      //Add('folgende Variablen werden verwendet:');
      if writeLog=true then Add('Schreiben der Logfile aktiv') else Add('Schreiben der Logfile NICHT aktiv');
      Add('Logfile wird in '+logFile+' gespeichert');
      //test
      for i:=1 to StartParam.Count-1 do Add(StartParam[i]);
    end;
end;

procedure TMainForm.SetStartParam(tmpStartParam: TStringList);
var
  i: integer;
begin
  StartParam:=tmpStartParam; //übernehmen der Startparameter

  if StartParam.Count>0 then
    for i:=0 to StartParam.Count-1 do
      begin
        if Uppercase(StartParam[i])='LOG' then writeLog:=true else writeLog:=false;
        if Uppercase(StartParam[i])='LOGFILE' then logFile:=StartParam[i+1] else logFile:=ApplicationPath;
      end;
end;

end.


leider wird writeLog nicht true, den rest könnt ihr sicher selbst schnell lesen...


Vielen Dank schonmal,
Gruß
Michael Stenzel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 133


D3 Prof, D7 PE
BeitragVerfasst: Sa 09.12.06 01:30 
Hi Moonbiker.

Versuche mal in deiner Main-Unit die Stringliste mit Assign zuzuweisen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
// Original -> StartParam:=tmpStartParam; //übernehmen der Startparameter 
  StartParam.Assign(tmpStartParam);
...


Gruß
Michael.
Moonbiker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Sa 09.12.06 08:27 
hat leider nicht zum Erfolg geführt...

Aber Danke! Was ändert sich dadurch eigentlich?
Reinhard Kern
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 591
Erhaltene Danke: 14



BeitragVerfasst: Sa 09.12.06 10:05 
user profile iconMoonbiker hat folgendes geschrieben:
Hi, schön wieder hier zu sein.

Ich möchte eine Anwendung per Startparamter steuern (später über geplante tasks...), nur werden übergebene Parameter zwar richtig eingelesen, nur reagiert mein Programm nicht drauf, und ich hoffe ihr weist mich auf einen sicher schnell zu finden aber von mir scheinbar immerwieder übersehehen Fehler hin, damits weiter gehen kann.

...
leider wird writeLog nicht true, den rest könnt ihr sicher selbst schnell lesen...


Vielen Dank schonmal,
Gruß


Hallo,

du kannst paramstr bestimmt nicht verwenden, bevor die Applikation initalisiert ist. Das geht erst direkt vor Application.run.

Gruss Reinhard
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 09.12.06 11:26 
@Reinhard: stimmt nicht ;)

Das Problem wird aber daran liegen, dass du wenn der Parameter Log kommt, WriteLog auf true setzt. der nächste Parameter (logfile) setzt dann aber writeLog wieder auf false.

Also versuchs mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TMainForm.SetStartParam(tmpStartParam: TStringList);
var
  i: integer;
begin
  StartParam.Assign(tmpStartParam); //übernehmen der Startparameter

  // Standardwerte, wenn Parameter nicht da
  writeLog:=false
  logFile:=ApplicationPath;

  // einlesen
  if StartParam.Count>0 then
    for i:=0 to StartParam.Count-1 do
      begin
        if Uppercase(StartParam[i])='LOG' then writeLog:=true;
        if Uppercase(StartParam[i])='LOGFILE' then logFile:=StartParam[i+1];
      end;
end;


Assign kopiert übrigens die StringListe, statt nur den Zeiger zu setzen.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Moonbiker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Sa 09.12.06 12:14 
VIELEN DANK,
das war der Fehler, klar, wird ja mehrmals durchlaufen, DANKE.

Und ich möchte ein assign, genau, also dafür auch danke ;)

Gruß und frohes Fest!