Bei soviel Hilfe war es ja nicht schwer, das Programm schnell zu schreiben.
Hier mein Code, wen´s interessiert... ist eigentlich total einfach.
(Ich verwende 4 Buttons, Save- u. Opendialog, Memo, Statusbar)
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:
| procedure TForm1.BtBtnOpenINIClick(Sender: TObject); //Öffnet den OpenDialog und setzt Attribute der Buttons außerdem Informationen //zur Datei in der Statusleiste
begin if OpenDialog1.Execute then MemoInIdat.Lines.LoadFromFile(OpenDialog1.FileName);
BtBtnSaveINI.Visible := true; BtBtnSaveINI.Enabled := false; BtBtnSortINI.Visible := true; StatusBar1.Panels.Items[0].Text := 'Datei: ' + OpenDialog1.FileName; StatusBar1.Panels.Items[1].Text := 'Zeilen: ' + IntToStr(MemoInIdat.Lines.Count-1); StatusBar1.Panels.Items[2].Text := 'Größe: ' + IntToStr(SizeOf(OpenDialog1.Name)) + ' KB'; end;
//************************************************************ procedure TForm1.MemoInIdatChange(Sender: TObject); //Fals der Text verändert wird wird der SaveButton sichtbar
begin BtBtnSaveINI.Enabled := true; end;
//************************************************************ procedure TForm1.BtBtnSaveINIClick(Sender: TObject); //Speichert Datei und überprüft ob es sich um eine neue od. geöffnete Datei handelt
begin if OpenDialog1.FileName <> '' then MemoInIdat.Lines.SaveToFile(OpenDialog1.FileName) else SaveDialog1.Execute; end;
//************************************************************ procedure TForm1.BtBtnSortINIClick(Sender: TObject); //Beginnt mit der Sortierroutine
begin SearchString; end;
//************************************************************ procedure TForm1.SearchString; //Sortierroutine
var iPosIndex, iLoop, iFileLength, iFileCount: integer; SubStr, sLine : string; bEdtArea : boolean; //gibt an ob es sich um den zu bearbeitenden Bereich handelt begin MemoInIdat.Lines.BeginUpdate; iFileLength := MemoInIdat.Lines.Count-1; SubStr := '='; iFileCount := 1; //Dateicounter
//iLoop durchläuft die TextDatei von Zeile 1 - x for iLoop := 0 to iFileLength do begin //Zeile x wird gelesen sLine := MemoInIdat.Lines[iLoop];
//Inoriere Zeile if (Pos('[SourceFiles]',sLine) <> 0) then begin bEdtArea := True; Continue; end;
//Inoriere Zeile if (Pos('CurrentPath',sLine) <> 0) and bEdtArea then Continue;
//Inoriere Zeile if (sLine = '') and bEdtArea then Continue;
//Suche Index von SubStr iPosIndex := Pos(SubStr,sLine);
//Index gefunden? Beginne mit der Verarbeitung if (iPosIndex <> 0) and bEdtArea then begin AddCount(iLoop, iFileCount, sLine); inc(iFileCount); end;
//Ende des zu bearbeitenden Bereiches? if (Pos('[',sLine) <> 0) and bEdtArea then Break;
end;
MemoInIdat.Lines.EndUpdate; end;
//************************************************************ procedure TForm1.AddCount(iCountLine, iFileCount: integer; sLine: string); begin //Vorderen Teil der Zeile bis '=' abschneiden Delete(sLine,1,pos('=',sLine)); //Vorderen Teil neu schreiben und den Rest nach = anhängen MemoInIdat.Lines[iCountLine] := Format('File' + '%s' + ' =',[IntToStr(iFileCount)]) + sLine; end;
//************************************************************ procedure TForm1.BtBtnNewClick(Sender: TObject); begin //Grundstrucktur anlegen MemoInIdat.Lines.Add('[SourceFiles]'); MemoInIdat.Lines.Add('CurrentPath = '); MemoInIdat.Lines.Add(' '); MemoInIdat.Lines.Add('File1 = '); MemoInIdat.Lines.Add(' '); MemoInIdat.Lines.Add('[ ]'); BtBtnSaveINI.Visible := true; BtBtnSortINI.Visible := true; end;
//************************************************************ procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin //Sicherheitsabfrage, damit Daten nicht verloren gehen if BtBtnSaveINI.Enabled then if MessageDlg('Die Datei wurde verändert. Möchten Sie die Änderungen speichern?' ,mtInformation,[mbYes, mbNo], 0) = mrYes then begin BtBtnSaveINI.Click; end; end; |
Gut, man könnte die Searchroutine direkt in den Sortbutton schreiben.
Und der Code ist nicht perfekt.
Der Aufbau der INI sieht in der Regel so aus:
[SourceFiles]
CurrentPath =
FileX =
[Zip]
Stellen Sie sich bitte Zirkusmusik vor.