Einzelnen Beitrag anzeigen

s-off
(Gast)

n/a Beiträge
 
#4

Re: [TListView] Veränderte Spaltenanordnung speichern

  Alt 10. Mai 2006, 21:16
Hallo,

Speicherung in Ini funktioniert beispielsweise:

Delphi-Quellcode:
unit Unit1;

interface

uses
   Windows,
   Messages,
   SysUtils,
   Variants,
   Classes,
   Graphics,
   Controls,
   Forms,
   Dialogs,
   StdCtrls,
   ComCtrls,
   IniFiles;

type
   TForm1 = class(TForm)
      ListView1: TListView;
      procedure SaveCols(ListView: TListView);
      procedure LoadCols(ListView: TListView);
      procedure FormClose(Sender: TObject; var Action: TCloseAction);
      procedure FormShow(Sender: TObject);
   private
      { Private-Deklarationen }
      Ini: TIniFile;
   public
      { Public-Deklarationen }
   end;

var
   Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
   ListItem: TListItem;
begin
   Ini := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'myini.ini');
   LoadCols(ListView1);
end;

procedure TForm1.LoadCols(ListView: TListView);
var
   i: Integer;
begin
   for i := 0 to ListView1.Columns.Count - 1 do begin
      ListView1.Column[i].Index := Ini.ReadInteger('columns', ListView1.Column[i].Caption, ListView1.Column[i].Index);
   end;
end;

procedure TForm1.SaveCols(ListView: TListView);
var
   i: Integer;
begin
   for i := 0 to ListView1.Columns.Count - 1 do begin
      Ini.WriteInteger('columns', ListView1.Column[i].Caption, ListView1.Column[i].Index);
   end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   SaveCols(ListView1);
   FreeAndNil(Ini);
end;

end.
  Mit Zitat antworten Zitat