![]() |
Array of String in Datei speichern
Nabend ;-),
ich habe zurzeit ein Array of String. Das Array ist mit vielen Wörtern gefüllt, die ich jetzt gerne in eine Datei speichern möchte. Beim nächsten Programmstart sollen dann automatisch alle Wörter aus der Datei in das Array geladen werden. Wie bewerkstellige ich dies?
Delphi-Quellcode:
ich hab z.B. jetzt diesen Delphi Code gefunden, aber so ganz verstehe ich nicht wie ich das machen kann das der
var
myFile : TextFile; text : string; begin // Try to open the Test.txt file for writing to AssignFile(myFile, 'Test.txt'); Write(myFile); // Write a couple of well known words to this file WriteLn(myFile, 'Hello'); //WriteLn(myFile, 'World'); // Close the file CloseFile(myFile); // Reopen the file for reading Reset(myFile); // Display the file contents while not Eof(myFile) do begin ReadLn(myFile, text); ShowMessage(text); end; // Close the file for the last time CloseFile(myFile); end; das Array füllt?! z.B.:
Delphi-Quellcode:
also er soll der Rheihe nach vorgehen und alles in das Array speichern?
for i := 0 to "Dateilänge bzw Menge des Inhalts" - 1 do ArrayString[i] := Inhalt NR. i
Wie muss ich da vorgehen? |
Re: Array of String in Datei speichern
Guten Abend,
ohne jetzt auf dein aktuelles Problem einzugehen, aber was bewegt Dich ein Array of String zu nutzen und nicht gleich eine TStringList (diese bringt sogar eine Lade- und Speicherroutine mit). [edit] zu deinem Problem:
Delphi-Quellcode:
Einlesen funktioniert analog.var myFile : TextFile; text : string; i : Integer: sArray : Array of String; begin // Try to open the Test.txt file for writing to AssignFile(myFile, 'Test.txt'); Write(myFile); // Write a couple of well known words to this file for i:=low(sArray) to high(sArray) do WriteLn(myFile, array[i]); // Close the file CloseFile(myFile); Allerdings solltest Du dann vorher die Größe des Array setzen. Grüße Klaus |
Re: Array of String in Datei speichern
Und jetzt noch eine schöne Fehlerbehandlung drumherum und Luckie ist glücklich. ;)
|
Re: Array of String in Datei speichern
Zitat:
Delphi-Quellcode:
var
myFile : TextFile; text : string; i : Integer: // hier will der Compiler ein ; sArray : Array of String; begin AssignFile(myFile, 'Test.txt'); Write(myFile); // und hier kracht's immer, richtig rewrite for i:=low(sArray) to high(sArray) do WriteLn(myFile, array[i]); //und hier wäre sArray angebracht CloseFile(myFile); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:19 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz