开发者

LoadToFile issue when trying to load .txt file into a string

开发者 https://www.devze.com 2023-04-12 23:27 出处:网络
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 Passwo

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消