Autor Beitrag
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mo 29.01.07 11:38 
HI,
hier erstma der Quelltext:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.LOAD(PageName,StringGrid,LoadFrom:String);
var i,j,Cols,Rows,LineCounter:Integer;
begin
  try
    Memo1.Lines.LoadFromFile(IntToStr(TabControl1.TabIndex)+'\'+LoadFrom+'.mek');
    Cols := TStringGrid(FindComponent(PageName+'_'+StringGrid)).ColCount-1;
    Rows := TStringGrid(FindComponent(PageName+'_'+StringGrid)).RowCount-1;
    LineCounter := 0;
    for i := 1 to Rows do
      for j := 0 to Cols do
        begin
          TStringGrid(FindComponent(PageName+'_'+StringGrid)).Cells[j,i] := Memo1.Lines[LineCounter];
          inc(LineCounter);
        end;
  except    
    for i := 1 to Rows do
      for j := 0 to Cols do
        TStringGrid(FindComponent(PageName+'_'+StringGrid)).Cells[j,i] := '';

  end;
end;


erstma zur erleuterung:
page_name+'_'+StringGrid ist der name des Grids.
und LoadFrom ist der name der datei.

So jetzt zum Problem: wenn die Datei die ins memo geladen wird nicht da ist,
dann geht er ja automatisch in die except-anweisung, und da bleibt er dann
jedesmal hängen. weiß jemand wie man das lösen kann oder ob es ne bessere
lösung zum löschen von dem grid gibt ?!

MfG & Thx Bergmann.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 29.01.07 11:54 
user profile iconBergmann89 hat folgendes geschrieben:
wenn die Datei, die ins memo geladen wird, nicht da ist,
dann geht er ja automatisch in die except-anweisung
Das ist schon richtig, aber auch bei jedem anderen Fehler im Try-Block.
Bist Du schonmal schrittweise durchgegangen, ob der Fehler nicht woanders liegt?
ssb-blume
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 375
Erhaltene Danke: 7

XP, W7, W8
Deutschland
BeitragVerfasst: Mo 29.01.07 13:16 
Hallo,
zuerst mal vereinfachen und dann so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.LOAD(PageName,StringGrid,LoadFrom:String);
var i,j,Cols,Rows,LineCounter:Integer;
    StrGr: TStringGrid;
begin
  StrGr:=TStringGrid(FindComponent(PageName+'_'+StringGrid));
  for i := 1 to Rows do// erst alles loeschen
      for j := 0 to Cols do StrGr.Cells[j,i] := '';
  if not fileexists(IntToStr(TabControl1.TabIndex)+'\'+LoadFrom+'.mek') then exit;
  // hier weiter, wenn file da:
  Memo1.Lines.LoadFromFile(IntToStr(TabControl1.TabIndex)+'\'+LoadFrom+'.mek');
  Cols := StrGr.ColCount-1;
  Rows := StrGr.RowCount-1; 
  LineCounter := 0;
  for i := 1 to Rows do
    for j := 0 to Cols do
    begin
      StrGr.Cells[j,i] := Memo1.Lines[LineCounter];
      inc(LineCounter);
    end;
  end;
end;


Ist der Filename denn richtig? es fehlt Laufwerk...

_________________
Brain: an apparatus with which we think we think.
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mo 29.01.07 13:23 
ne, aber der Fehler kommt bloß wenn die datei nicht da ist.
ich kann ja ma das prog noch hochladen...

Der Fehler kommt wenn du zwischen den Seiten von dem oberen TabControl
hin und her wechselst und die Datei aus der er die Daten läd nicht da ist.
Das komiche ist, wenn ich im PageControl switche und die Datei fehlt, dann
macht er das was er soll also er löscht den inhalt des Grids...

€: Wir habens gefunden...Danke ssb-blume :P
Einloggen, um Attachments anzusehen!