Easiest way is to create a stringlist and read the file into it -
For an example, put a memo on your form and a button, and in the on-click for the button put Memo1.Lines.LoadFromFile(filenamehere);
The harder (but sometimes more useful!) way is this:
procedure OpenFile();
var myFile: TextFile;
line: string;
begin
assignfile(myFile, filenamehere);
reset(myfile);
try
while not eof(myfile) do
begin
readln(myFile, line);
//do something with the newly read
//string here
end;
finally
closefile(myfile)
end;
end;
It depends of what type of file you want to read.
TealWren has the ultimate way to read raw text files, but if you want to read standard ini-files you should use TIniFile.
Example Code (You must implement IniFiles in the Uses clause:
function ReadIniFile(FileName: String; Section, Prop, Value, Default: String): String;
begin
with TIniFile.Create(Filename) do
try
Result := ReadString(Section, Prop, Default);
finally
Free;
end;
end;
Example of ini-file
[Section]
Property=Value
If you want to retrieve the value above, just call my function like this:
s := ReadIniFile('Section','Property','Default when not found');
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.