I am currently working on a program for creating file hashes in Delphi 2010. As part of this, I have the ability to create custom presets, for example. predefined selection of a hashing algorithm that the user can create / save / delete. I have a create and load code that works fine. It uses a ComboBox and is loaded from the file "fhpre.ini", inside this file user presets are stored in the format: -
Presetname
PresetCode (12-bit string using 0 for non-hash and 1 for do)
When loading the application, it loads the data from this file into ComboBox and Array with ItemIndex from ComboBox corresponding to the correct line 0 and 1 in the array.
Now I need to implement a function so that the user removes the preset from the list. So far, my code is as follows:
procedure TForm1.Panel23Click(Sender : TObject); var fil : textfile; contents : TStringList; x,i : integer; filline : ansistring; filestream : TFileStream; begin //Start Procedure //Load data into StringList contents := TStringList.Create; fileStream := TFileStream.Create((GetAppData+'\RFA\fhpre.ini'), fmShareDenyNone); Contents.LoadFromStream(fileStream); fileStream.Destroy(); //Search for relevant Preset i := 0; if ComboBox4.Text <> Contents[i] then begin Repeat i := i + 1; Until ComboBox4.Text = Contents[i]; end; contents.Delete(i); //Delete Relevant Preset Name contents.Delete(i); //Delete Preset Digit String //Write StringList back to file. AssignFile(fil,(GetAppData+'\RFA\fhpre.ini')); ReWrite(fil); for i := 0 to Contents.Count -1 do WriteLn(Contents[i]); CloseFile(fil); Contents.Free; end;
However, if this is done, I get an error 105 when it gets to the WriteLn section. I know that the code is small, for example, it does not have checks for presets with the same name, but this will happen, I want to run the base code first, and then configure and add additional checks, etc.
Any help would be greatly appreciated.
source share