unit ELVSup;
interface
uses
  IniFiles, 
  ExtListView;
procedure ELVWriteSettingsToIniFile(AListView: TdfsExtListView; Value: String; IniFile: TIniFile);
procedure ELVReadSettingsFromIniFile(AListView: TdfsExtListView; Value: String; IniFile: TIniFile);

implementation
uses
  SysUtils;

procedure ELVWriteSettingsToIniFile(AListView: TdfsExtListView; Value: String; IniFile: TIniFile);
var
  x: integer;
  s: string;
begin
  with AListView do
  begin
    //Don't save the size of the first column
    if Columns.Count < 1 then Exit;
    for x := 1 to Columns.Count-1 do
     s := s + IntToStr(ActualColumn[x].Width) + ',';
     SetLength(s, Length(s)-1);
     IniFile.WriteString(Value, 'ColumnSizes', s);
     //sorting
     IniFile.WriteBool(Value, 'Sort', CurrentSortAscending);
     IniFile.WriteInteger(Value, 'SortCol', LastColumnClicked);
   end;
end;

procedure ELVReadSettingsFromIniFile(AListView: TdfsExtListView; Value: String; IniFile: TIniFile);
var  x,y: integer;
     s: string;
begin
  with AListView do
  begin
    //Don't change the size of the first column
    if Columns.Count < 1 then Exit;
    s := IniFile.ReadString(Value, 'ColumnSizes', '');
    if s = '' then Exit;
    y := 0;
    for x := 1 to Columns.Count-1 do 
    begin
      try
        y := Pos(',', s);
        if y = 0 then y := Length(s)+1;
        ActualColumn[x].Width := StrToInt(Copy(s, 1, y-1));
      except
        ActualColumn[x].Width := 0;
      end;
      s := copy(s, y+1, length(s));
      if s = '' then break;
    end;
    //sorting
    try
      CurrentSortAscending := IniFile.ReadBool(Value, 'Sort', TRUE);
      LastColumnClicked := IniFile.ReadInteger(Value, 'SortCol', 0);
      if LastColumnClicked >= Columns.Count then LastColumnClicked := Columns.Count-1;
      if LastColumnClicked < 0 then LastColumnClicked := 0;
      BeginUpdate;
      Resort;
      EndUpdate;
    except
      EndUpdate;
    end;
  end;
end;
end.
