Hi...
Deinen letzten satz verstehe ich irgendwie nicht so recht: Willst du den Inhalt des Files in einem memo und in nem StringGrid??
Um deine Spalten im Textfile zu separieren, hast du 5 Leerzeichen verwendet, ich würde dir hier eher z. B. zum Tabulator raten!
Fogendermassen kannst du dein Textfile in nen Stringgrid laden, vorausgesetzt er verfüght über 3 Spalten:
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:
| procedure ClearGrid(strGrid: TStringGrid); var i: Integer; begin with strGrid do begin RowCount := 2; for i:=0 to ColCount-1 do begin strGrid.Cells[i, 1] := ''; end; end; end;
function AddLineToStrGrid(line: String; strGrid: TStringGrid; separator: String): Integer; var pos: Integer; begin Result := 0; strGrid.RowCount := strGrid.RowCount+1; pos = Pos(separator, line); while not (pos = 0) do begin strGrid.Cells[Result, strGrid.RowCount-1] := Copy(line, 1, pos-1); Inc(Result); line := Delete(line, 1, pos+Length(separator)-1) pos = Pos(separator, line); end; strGrid.Cells[Result, strGrid.RowCount-1] := line; Inc(Result); end;
functionLoadFromFile(fileName: TFileName; strGrid: TStringGrid): Boolean; var iFile: TextFile; line: String; begin Result := False; AssignFile(iFile, fileName); {$I-} Reset(iFile); {$I+} if not (IOResult = 0) then Exit; while not Eof(iFile) do begin ReadLn(iFile, line); if not (AddLineToStrGrid(line, strGrid, ' ') = 3) then begin ClearGrid(strGrid); Exit; end; end; closeFile(iFile); Result := True; end; |
Ich habe das ganze nur kurz geschrieben, habe es NICHT getestet! Aber zumindest so ähndlich müsste es klappen!
Grüsse Dominic