| Autor |
Beitrag |
DaKirsche
      
Beiträge: 187
Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
|
Verfasst: Sa 18.08.07 22:53
Hallo Community,
ich erarbeite gerade ein Tool zum Verwalten von Meterialausgaben in meinem "Betrieb" und stehe nun vor einem kleinen Problem:
Ich habe eine Unit erstellt, mit der ich eine Art des Loggen durchführen will und dabei tritt mir ein Fehler auf.
Hier erstmal der Code:
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: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173:
| unit Logging;
interface uses Grids, SysUtils, Forms; type TLogData = record Index : Integer; Timestamp : TDateTime; HeadLine : String[50]; Short : String[30]; Long : String[255]; User : String[25]; end;
TItems = record Data : File of TLogData; FileName : String; FilePath : String; ItemIndex : Integer; end;
TLog = class private Items: TItems; function setFile(a_FileName,a_Path: String):Boolean; function goToEof():Boolean; function preventGrid(OutputGrid: TStringGrid):Boolean; function outputGridLine(OutputGrid: TStringGrid; OutputData: TLogData): Boolean; public Constructor Create(a_file : String; a_Path: String); Destructor Destroy(); override; function add(a_Data: TLogData):Boolean; function FileName:String; function ItemIndex:Integer; function FilePath:String; function NextLine: Integer; function DisplayLogFile(OutputGrid: TStringGrid): Integer; end; var RowCt: Integer = 0;
implementation
Constructor TLog.Create(a_File: String; a_Path: String); begin inherited Create; setFile(a_File,a_Path); end;
Destructor TLog.Destroy; begin CloseFile(Items.Data); Items.ItemIndex:= 0; inherited; end;
function TLog.setFile(a_FileName,a_Path: string):Boolean; var a_Data: TLogData; begin AssignFile(Items.Data,a_Path+a_fileName); Items.FileName:= a_FileName; Items.FilePath:= a_Path; Items.ItemIndex := 0; Reset(Items.Data); while not Eof(Items.Data) do begin Read(Items.Data,a_Data); Items.ItemIndex := Items.ItemIndex + 1; end; end;
function TLog.add(a_Data: TLogData):Boolean; begin result:=true; if goToEof() then write(ITems.Data, a_Data) else Result:=False; end;
function TLog.goToEof():Boolean; var a_Data: TLogData; begin Reset(Items.Data); Result := False; while not Eof(Items.Data) do begin Read(Items.Data,a_Data) end; Result := True; end;
function TLog.FileName: String; begin result:=Items.FileName; end;
function TLog.ItemIndex: Integer; begin result:=Items.ItemIndex; end;
function TLog.FilePath: String; begin Result := Items.FilePath; end;
function TLog.NextLine:Integer; var a_Data: TLogData; begin Reset(Items.Data); Result := 1; while not Eof(Items.Data) do begin Read(Items.Data,a_Data); Result := Result + 1; end; end;
function TLog.DisplayLogFile(OutputGrid: TStringGrid):Integer; var a_Data: TLogData; begin Result := -1; if preventGrid(OutputGrid) then begin Reset(Items.Data); Result:=0; while not Eof do begin Read(Items.Data,a_Data); Result := Result + 1; outputGridLine(OutputGrid,a_Data); end; end; end;
function TLog.preventGrid(OutputGrid: TStringGrid):Boolean; begin Result:=False; With OutputGrid do begin if NextLine > 2 then RowCount := NextLine else RowCount := 2; FixedCols := 0; FixedRows := 1; ColCount := 6; Cells[0,0]:='ID'; Cells[1,0]:='Datum'; Cells[2,0]:='Uhrzeit'; Cells[3,0]:='Vorgang'; Cells[4,0]:='Benutzer'; Cells[5,0]:='Status'; ColWidths[0]:=30; ColWidths[1]:=70; ColWidths[2]:=70; ColWidths[3]:=150; ColWidths[4]:=150; ColWidths[5]:=150; DefaultRowHeight:=17; RowCt:=0; Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goColSizing,goRowSelect]; Result:=True; end; end;
function TLog.outputGridLine(OutputGrid: TStringGrid; OutputData: TLogData):Boolean; begin Result := False; With OutputGrid do begin Inc(RowCt,1); Cells[0,RowCt]:=IntToStr(OutputData.Index); Cells[1,RowCt]:=DateToStr(OutputData.Timestamp); Cells[2,RowCt]:=TimeToStr(OutputData.Timestamp); Cells[3,RowCt]:=OutputData.HeadLine; Cells[4,RowCt]:=OutputData.User; Cells[5,RowCt]:=OutputData.Short; Application.Processmessages(); end; Result := True; end;
end. |
und an der Stelle:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
| function TLog.outputGridLine(OutputGrid: TStringGrid; OutputData: TLogData):Boolean; begin Result := False; With OutputGrid do begin Inc(RowCt,1); Cells[0,RowCt]:=IntToStr(OutputData.Index); Cells[1,RowCt]:=DateToStr(OutputData.Timestamp); Cells[2,RowCt]:=TimeToStr(OutputData.Timestamp); Cells[3,RowCt]:=OutputData.HeadLine; Cells[4,RowCt]:=OutputData.User; Cells[5,RowCt]:=OutputData.Short; Application.Processmessages(); end; Result := True; end; |
tritt ein
E/A Fehler 6
auf.
Kann mir eine(r) sagen, wo der Fehler dran liegen könnte?
Der Aufruf an der Funktion befindet sich auf einer anderen Unit folgendermaßen:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| [...] uses [...],logging; [...] function TForm2.showitems(a_Path,a_Data:String): Boolean; begin Log := TLog.Create(a_Data,a_Path); Log.DisplayLogFile(StringGrid1); Log.Destroy; end; [...] |
Also das Stringgrid wird ordnungsgemäß vorbereitet, die Logdatei existiert und das Schreiben funktioniert auch.
Hat irgendjemand eine Idee, was passiert sein könnte?
Apropos:
Die Form "TForm2" wird folgendermaßen aufgerufen:
Delphi-Quelltext 1: 2: 3: 4: 5: 6:
| procedure TMain_Window.SpeedButton10Click(Sender: TObject); begin Application.CreateForm(TForm2, Form2); Form2.Show; Form2.showitems(ProgrammDir+'Logs\','access.log'); end; |
Mfg
DaKirsche
_________________ Die simpelsten Fehler sind meist die Schwersten...
|
|
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Sa 18.08.07 23:12
Einen E/A Fheler 6 kennt meine Delphihilfe nicht. Nur Werte von 100 bis 106 unter dem Stichwort I/O Errors.
Wo hast du eigentlich deine Fehlerbehandlung? Bzw. wo tritt der Fehler aufß
|
|
DaKirsche 
      
Beiträge: 187
Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
|
Verfasst: Sa 18.08.07 23:23
hmm...der Fehler tritt in der Funktion "outputGridLine(OutputGrid: TStringGrid; OutputData: TLogData):Boolean;" auf.
Also die Einstellungen am Stringgrid führt das Programm noch durch und danach tritt der Fehler dann auf.
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:
| function TLog.DisplayLogFile(OutputGrid: TStringGrid):Integer; var a_Data: TLogData; begin Result := -1; if preventGrid(OutputGrid) then begin Reset(Items.Data); Result:=0; while not Eof do begin Read(Items.Data,a_Data); Result := Result + 1; outputGridLine(OutputGrid,a_Data); end; end; end;
function TLog.preventGrid(OutputGrid: TStringGrid):Boolean; begin Result:=False; With OutputGrid do begin if NextLine > 2 then RowCount := NextLine else RowCount := 2; FixedCols := 0; FixedRows := 1; ColCount := 6; Cells[0,0]:='ID'; Cells[1,0]:='Datum'; Cells[2,0]:='Uhrzeit'; Cells[3,0]:='Vorgang'; Cells[4,0]:='Benutzer'; Cells[5,0]:='Status'; ColWidths[0]:=30; ColWidths[1]:=70; ColWidths[2]:=70; ColWidths[3]:=150; ColWidths[4]:=150; ColWidths[5]:=150; DefaultRowHeight:=17; RowCt:=0; Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goColSizing,goRowSelect]; Result:=True; end; end;
function TLog.outputGridLine(OutputGrid: TStringGrid; OutputData: TLogData):Boolean; begin Result := False; With OutputGrid do begin Inc(RowCt,1); Cells[0,RowCt]:=IntToStr(OutputData.Index); Cells[1,RowCt]:=DateToStr(OutputData.Timestamp); Cells[2,RowCt]:=TimeToStr(OutputData.Timestamp); Cells[3,RowCt]:=OutputData.HeadLine; Cells[4,RowCt]:=OutputData.User; Cells[5,RowCt]:=OutputData.Short; end; Result := True; end; |
Wie auf dem Bild zu sehen ist wird das Stringgrid entsprechend vorbereitet, aber mehr passiert leider nicht...
Einloggen, um Attachments anzusehen!
_________________ Die simpelsten Fehler sind meist die Schwersten...
|
|
DaKirsche 
      
Beiträge: 187
Win XP Pro, SuSe Linux 7.3 - 10.2, Win 2k3 Server, Win 2000, Win NT 4.0
Delphi 2006 Pro, Java, HTML, SQL, PHP, CSS
|
Verfasst: So 19.08.07 00:11
Ok...Fehler gefunden - Problem gelöst....trotzdem danke!
Hier die Funktion, wie sie funktioniert:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
| function TLog.DisplayLogFile(OutputGrid: TStringGrid):Integer; var a_Data: TLogData; begin Result := -1; if preventGrid(OutputGrid) then begin Reset(Items.Data); Result:=0; while not Eof(Items.Data) do begin Read(Items.Data,a_Data); Result := Result + 1; outputGridLine(OutputGrid,a_Data); end; end; end; |
_________________ Die simpelsten Fehler sind meist die Schwersten...
|
|
|