Autor Beitrag
Gintonik
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66

Win MCE 2005
Delphi7 Enterpr.
BeitragVerfasst: Di 27.03.07 16:50 
Hallo, ich habe in meinem Programm mehrere Opendialoge. Ich kann die Dateien öffnen und er verarbeitet die auch. Mein Problem taucht auf, wenn ich den Dialog öffne, keine Datei wähle und auf abbrechen klicke. Dann kommt eine Fehlermeldung (Out of Bounds...). Wie kann ich die unterdrücken?

THX, Marcel

_________________
Man sagt, er habe magische Kräfte!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 27.03.07 16:53 
Hallo!

Da ich nicht glaube, dass das ein Bug im OpenDialog selber ist, werden wir wohl die Prozedur sehen müssen, in der der OpenDialog aufgerufen wird, um Dir zu helfen. Sonst kann man da wenig zu sagen.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Di 27.03.07 16:53 
ausblenden Delphi-Quelltext
1:
2:
3:
try
except
end;

ist immer 'ne komfortable Lösung. Aber eigentlich dürfte dein Problem nicht auftreten, wenn du alles korrekt machst. Poste dochmal etwas Code.

Gruß

Calculon
--
Gintonik Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66

Win MCE 2005
Delphi7 Enterpr.
BeitragVerfasst: Di 27.03.07 16:55 
So greife ich auf meine Dateien zu...

ausblenden Delphi-Quelltext
1:
2:
if OpenDialog1.Execute then
    F.LoadFromFile(OpenDialog1.FileName);

_________________
Man sagt, er habe magische Kräfte!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 27.03.07 16:57 
Wenn der OpenDialog nicht mit "OK" beendet wird, ist F (was immer das genau ist ;-)) leer. Falls Du das nicht prüfst, kann es leicht passieren, dass Du auf einen Eintrag zugreifen willst, der gar nicht da ist.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 27.03.07 16:59 
user profile iconGintonik hat folgendes geschrieben:
So greife ich auf meine Dateien zu...

ausblenden Delphi-Quelltext
1:
2:
if OpenDialog1.Execute then
    F.LoadFromFile(OpenDialog1.FileName);

Genau. Die Execute-Methode ist eine Funktion, deren Rückabewert ein Boolean-Wert ist. Sie gibt true zurück, wenn auf ok, und false, wenn auf Abbrechen gedrückt wurde.
Ist es garantiert, dass FileName leer ist, wenn man auf Abbrechen drückt, Christian? Ich glaube, wenn eine Datei ausgewählt ist, dann ist FileName auch im Abbrechen-Fall gleich dem Pfad der ausgewählten Datei.
Kann mich aber auch täuschen ;)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Gintonik Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66

Win MCE 2005
Delphi7 Enterpr.
BeitragVerfasst: Di 27.03.07 16:59 
F ist ein zur LAufzeit erzeugtes Stringgrid
Hier ist der ganze Qualcode...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.LoadStringGridFromFile(StringGrid: TStringGrid);
var
  F: TStringList;
  i: Integer;
begin
  F := TStringList.Create;
  try
  if OpenDialog1.Execute then
    F.LoadFromFile(OpenDialog1.FileName);
    StringGrid.RowCount := StrToInt(F[0]);
    StringGrid.ColCount := StrToInt(F[1]);
    for i := 0 to (StringGrid.RowCount - 1do
      StringGrid.Rows[i].CommaText := F[i + 2];
  finally
    F.Free;
  end;
end;

_________________
Man sagt, er habe magische Kräfte!
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 27.03.07 17:03 
Da fehlen wohl begin...end ;-)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.LoadStringGridFromFile(StringGrid: TStringGrid);
var
  F: TStringList;
  i: Integer;
begin
  F := TStringList.Create;
  try
  if OpenDialog1.Execute then
  begin
    F.LoadFromFile(OpenDialog1.FileName);
    StringGrid.RowCount := StrToInt(F[0]);
    StringGrid.ColCount := StrToInt(F[1]);
    for i := 0 to (StringGrid.RowCount - 1do
      StringGrid.Rows[i].CommaText := F[i + 2];
  end;
  finally
    F.Free;
  end;
end;

_________________
We are, we were and will not be.
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Di 27.03.07 17:03 
Da fehlt einfach nur ein Begin und ein End, damit der ganze Bereich nur ausgeführt wird, wenn der Dialog mit OK bestätigt wurde.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Gintonik Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66

Win MCE 2005
Delphi7 Enterpr.
BeitragVerfasst: Di 27.03.07 17:08 
Das isses Jungs, SUPER !!! Ich glaube ich brauche so langsam ne Brille ;-)

_________________
Man sagt, er habe magische Kräfte!