LoadToFile issue when trying to load .txt file into a string
After my previous question of SavingToFile with TStringList, I now need to load the file I created called Password.txt using LoadFromFile but I don´t know what the form of LoadFromFile is. The Password.txt is in the same fold开发者_运维问答er as the program that needs to load it but I keep getting Access Violation at different addresses when I try LoadToFile in the way I thought it would work. How to I load Password.txt to a string in Delphi without getting a violation ?
Please help
var
StringList: TStringList;
...
StringList := TStringList.Create;
try
StringList.LoadFromFile('myfile.txt');
//do stuff with StringList
finally
StringList.Free;
end;
You are probably forgetting to create the string list properly with code like this:
StringList.Create;//don't do this
or
StringList.LoadFromFile('myfile.txt');//must create StringList first
But without seeing your code all we can do is guess as to what your problem is. That said, the first sample of code above is correct.
加载中,请稍侯......
精彩评论