Entwickler-Ecke

Grafische Benutzeroberflächen (VCL & FireMonkey) - [VisualCLX] Nach Öffnen einer Datei kann man kein Image mehr laden


eruhenon - Fr 13.04.07 00:12
Titel: Nach Öffnen einer Datei kann man kein Image mehr laden
Moin!
Ich schreib ja grade einen SGF-Reader. Nun hab ich die Oberfläche erstellt und es geschafft, dass wenn cih auf ein Feld klicke ein Stein erschient. Allerdings funktioniert dieses nur solange ich keine Datei geladen hab. Sobald ich eine SGF-Datei einlese erhalte ich eine Fehlermeldung, dass auf die Datei kein Zugriff möglich sei.


Darstellung auf dem Board:

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:
procedure TForm1.placestone(i:integer;j:integer);

Begin

        if (player) and (j=0and (i<>0and (i<>18then
                tarray[i,j].picture.loadfromfile('LeWaB.bmp')
        else if (player) and (j=0and (i=0then
                tarray[i,j].picture.loadfromfile('TLCB.bmp')
        else if (player) and (j=0and (i=18then
                tarray[i,j].picture.loadfromfile('BLCB.bmp')
        else if (player) and (j=18and (i<>0and (i<>18then
                tarray[i,j].picture.loadfromfile('RWB.bmp')
        else if (player) and (j=18and (i=0then
                tarray[i,j].picture.loadfromfile('TRCB.bmp')
        else if (player) and (j=18and (i=18then
                tarray[i,j].picture.loadfromfile('BRCB.bmp')
        else if (player) and (i=0and (j<>0and (j<>18and (i<>18then
                tarray[i,j].picture.loadfromfile('ToWaB.bmp')
        else if (player) and (i=18and (j<>0and (j<>18then
                tarray[i,j].picture.loadfromfile('BoWaB.bmp')
        else if (player) and (i<>0and (i<>18and (j<>0and (j<>18then
                tarray[i,j].picture.loadfromfile('MFB.bmp')
        else if (not player) and (j=0and (i<>0and (i<>18then
                tarray[i,j].picture.loadfromfile('LeWaW.bmp')
        else if (not player) and (j=0and (i=0then
                tarray[i,j].picture.loadfromfile('TLCW.bmp')
        else if (not player) and (j=0and (i=18then
                tarray[i,j].picture.loadfromfile('BLCW.bmp')
        else if (not player) and (j=18and (i<>0and (i<>18then
                tarray[i,j].picture.loadfromfile('RWW.bmp')
        else if (not player) and (j=18and (i=0then
                tarray[i,j].picture.loadfromfile('TRCW.bmp')
        else if (not player) and (j=18and (i=18then
                tarray[i,j].picture.loadfromfile('BRCW.bmp')
        else if (not player) and (i=0and (j<>0and (j<>18and (i<>18then
                tarray[i,j].picture.loadfromfile('ToWaW.bmp')
        else if (not player) and (i=18and (j<>0and (j<>18then
                tarray[i,j].picture.loadfromfile('BoWaW.bmp')
        else if (not player) and (i<>0and (i<>18and (j<>0and (j<>18then
                tarray[i,j].picture.loadfromfile('MFW.bmp')
end;


Öffnen der Datei:

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:
procedure TForm1.OpenSGF1Click(Sender: TObject);
var     sgffile : TextFile;
        buffer,gamefile,blacks,whites : string;
        p:integer;
begin
        gamefile:='';
        if form1.OpenDialog1.Execute then
        Begin
                AssignFile(sgffile,form1.OpenDialog1.FileName);
                Reset(sgffile) ;
                while not EOF(sgffile) do
                begin
                        readln(sgffile,buffer);
                        gamefile:=gamefile+buffer;
                end;
                CloseFile(sgffile);
                gamefile:=uppercase(gamefile);

                {if (pos('B[',gamefile)<pos('W[',gamefile)) then
                        player:=false
                else
                        player:=true;
                 }

                p:=pos('PB[',gamefile);
                delete(gamefile,p,6);
                p:=pos('PW[',gamefile);
                delete(gamefile,p,6);
                p:=pos('B[',gamefile);
                blacks:='';
                repeat
                        blacks:=blacks+copy(gamefile,p+2,2)+#13;
                        delete(gamefile,p,5);
                        p:=pos('B[',gamefile);
                until p=0;

                p:=pos('W[',gamefile);
                whites:='';
                repeat
                        whites:=whites+copy(gamefile,p+2,2)+#13;
                        delete(gamefile,p,5);
                        p:=pos('W[',gamefile);
                until p=0;

                black.Text:=lowercase(blacks);
                white.Text:=lowercase(whites);
        end;
end;


Danke für die Hilfe!


Lannes - Fr 13.04.07 00:32

Hallo,

die SGF-Datei wird in Deinem Code über einem OpenDialog ausgewählt.
Dadurch wird eventuell das Arbeitsverzeichnis geändert und stimmt nicht mehr mit dem Verzeichnis überein das beim ersten Aufruf von placestone das aktuelle Arbeitsverzeichnis war.

Daraus folgert das Problem in Deinem Code:

Delphi-Quelltext
1:
2:
if (player) and (j=0and (i<>0and (i<>18then  
  tarray[i,j].picture.loadfromfile('LeWaB.bmp')

Hier fehlt der vollständige Pfad.

Arbeitsverzeichnis ist nicht immer identisch mit Anwendungsverzeichnis. :mahn:


eruhenon - Fr 13.04.07 00:37

da ich es ja portabel halten möchte wie kann ich das arbeitsverzeichnis wieder aufs anwendungsverzeichnis setzen?


Lannes - Fr 13.04.07 00:39

Hallo,

mit ExtractFilePath(ParamStr(0)) bekommst Du das Anwendungsverzeichnis.


eruhenon - Fr 13.04.07 00:42

danke funktioniert!