Autor Beitrag
Adrian
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 314



BeitragVerfasst: So 21.12.03 23:30 
Servus!

Eine AVI-Datei soll auf dem Bildschirm ablaufen, bis eine der dynamisch erzeugten Schaltflächen gedrückt wird; dynamisch sind sie deshalb, weil zum Zeitpunkt der Programmerstellung nur bekannt ist, daß es maximal 10 Stück sind. Dann wird die AVI-Wiedergabe angehalten, das Programm minimiert und die mit der Schalfläche verknüpft Anwendung ausgeführt. Nach Beendigung der Letzteren geht's mit der Wiedergabe bei maximiertem Fenster wieder weiter.
Also griff ich zur "ballistischen Programmierung": Man ziele auf Programmende und arbeite gerdlinig darauf los.
Der untenstehende Programmauszug hat auch funktioniert (was nicht allein mein Verdienst ist), bis ich die Prozedur "MachButton " eingefügt habe, seitdem reagiert die Anwendung auf das Beenden mit einem Pointer-Access-Fehler und ich bin ziemlich zerknirscht.

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:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
var
  Form1: TForm1;
  AviDatei: String;
  ButtonZahl: Integer;
  Programmzeile, Buttontext: Array[1..10of String;
  Programm_Button: Array of TButton;

implementation

{$R *.dfm}

procedure RunProcessAndWait (aFilename: String);
var
  StartupInfo : TStartupInfo;
  ProcessInfo : TProcessInformation;
  Result: Boolean;
begin
  FillChar (StartupInfo, SizeOf (TStartupInfo), 0);
  StartupInfo.cb := Sizeof (TStartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW OR STARTF_USEPOSITION OR STARTF_USESIZE ;
  StartupInfo.wShowWindow := SW_SHOWDEFAULT;
  Result := CreateProcess (
      nil,
      pChar (aFilename),
      nil,
      nil,
      False,
      NORMAL_PRIORITY_CLASS,
      nil,
      nil,
      StartupInfo,
      ProcessInfo
    );
  If Result then
    WaitForSingleObject (ProcessInfo.hProcess, INFINITE);
  if ProcessInfo.hProcess <> 0 then
  begin
    CloseHandle (ProcessInfo.hProcess);
    Application.Restore;
    Form1.MediaPlayer1.Resume;
  end;
end;

procedure MachButton;
// Erzeugt die Steuerschaltfächen und macht sie sichtbar
// Außerdem machts Probleme beim Beenden
var
  Abstand, i: Integer;
begin
    SetLength(Programm_Button,ButtonZahl);
    Abstand:=(Form1.Height-(ButtonZahl*50)) div (ButtonZahl+1);
    if Abstand<2 then Abstand:=2;
    for i:=1 to ButtonZahl do
    begin
      Programm_Button[i]:=TButton.Create(Form1);
      with Programm_Button[i] do
      begin
        Parent:=Form1;
        Left:=(Form1.Width div 2)-75;
        Top:=(((i-1)*50)+(i*Abstand))-10;
        Width:=150 div 2;
        Height:=50 div 2;
        Name:='Programm'+IntToStr(i);
        Caption:=Buttontext[i];
        Programm_Button[i].BringToFront;
      end;// von with...
    end;// von for i...
end;

procedure TForm1.FormCreate(Sender: TObject);
// Von Anfang an auf Vollbild gehen
var
  ini: TIniFile;
  n: Integer;
begin
  WindowState:=wsMaximized;
// Parameterdatei auslesen
  ini:= TIniFile.Create(ExtractFilePath(ParamStr(0))+'AVI-Parameter.ini');
  ButtonZahl:=StrToInt(ini.ReadString('Anzahl','Menge','10'));
  for n:=1 to ButtonZahl do
  begin
    Programmzeile[n]:=ini.ReadString('Programmoptionen','Programm '+IntToStr(n),
                                     'C:\Programme\AVI\P'+IntToStr(n)+'.exe');
    Buttontext[n]:=ini.ReadString('Programmoptionen','Text '+IntToStr(n),
                                     'P'+IntToStr(n)+'.exe');
  end;
// AVI einlesen und starten
  AviDatei:=ini.ReadString('AVI-Angabe','AVI-Datei','C:\Programme\AVI\File.avi');
  ini.Free;
  Sam(nil);
end;

procedure TForm1.Sam(Sender: TObject);
// Abspielen der AVI-Datei
begin
  With MediaPlayer1 do begin
    Filename :=AviDatei;
    Display := Panel1;
    Open;
    Application.ProcessMessages;
    DisplayRect := Panel1.ClientRect;
    if MediaPlayer1.Mode<>mpPlaying then
    begin
      Play;
    end;
  end;
end;

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
// Film wiederholen, wenn zu Ende
begin
 Sam(nil);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.Minimize;
  MediaPlayer1.Pause;
  RunProcessAndWait('c:\windows\calc.exe');
end;

procedure TForm1.FormResize(Sender: TObject);
// Filmfenster ist genauso groß wie das Programmfenster
begin
  Panel1.Width:=Width;
  Panel1.Height:=Height;
  MediaPlayer1.DisplayRect := Panel1.ClientRect;
  Button1.BringToFront;
  Button2.BringToFront;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled:=False;
  MachButton;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  MediaPlayer1.Stop;
  MediaPlayer1.Close;
  Close;
end;

end.


Wenn mir jetzt einer sagen kann, woran es liegt, wäre ich recht froh, ebenso, wenn ich Informationen darüber bekomme, wie die Aufgabe professionell gelöst werden würde.

Gruß,

Adrian
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 21.12.03 23:35 
Hallo!

In der Prozedur "MachButton" verwendest Du den Befehl "SetLength(Programm_Button, ButtonZahl);". Damit gehen die Indizes von "Programm_Button" von 0 bis ButtonZahl -1. In der nachfolgenden Schleife sind die Indizes also um 1 verschoben. (von 1 bis ButtonZahl)

MfG
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".