Ver Mensaje Individual
  #3  
Antiguo 14-06-2018
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Otra opción para el TCheckListBox que requiere escribir un poquito más, pero te permite reutilizar los nuevos métodos añadidos cuando lo precises:
Código Delphi [-]
unit CheckListBoxEx;

interface

uses SysUtils, Classes, CheckLst;

type
  TCheckListBox = class(CheckLst.TCheckListBox)
  public
    procedure SaveToFile(const FileName: string);
    procedure LoadFromFile(const FileName: string);
  end;

implementation

procedure TCheckListBox.SaveToFile(const FileName: string);
var
  i: Integer;
  TS: TStrings;
begin
  TS := TStringList.Create;
  try
    for i := 0 to Self.Items.Count-1 do
      if Self.Checked[i] then
        TS.Add('*' + Self.Items[i])
      else
        TS.Add(' ' + Self.Items[i]);
    TS.SaveToFile(FileName);
  finally
    TS.Free;
  end;
end;

procedure TCheckListBox.LoadFromFile(const FileName: string);
var
  i: Integer;
  TS: TStrings;
begin
  if not FileExists(FileName) then
    raise Exception.Create('Archivo no encontrado');
  Self.Items.Clear;
  TS := TStringList.Create;
  try
    TS.LoadFromFile(FileName);
    for i := 0 to TS.Count-1 do
    begin
      Self.Items.Add(Copy(TS[i], 2, MaxInt));
      Self.Checked[i] := TS[i][1] = '*';
    end;
  finally
    TS.Free;
  end;
end;
end.

Ejemplo de uso:
Código Delphi [-]
unit Unit1;

interface

uses  ..., { siempre añadir última -> } CheckListBoxEx;

type
  TForm1 = class(TForm)
    CheckListBox1: TCheckListBox;
    btnSave: TButton;
    btnLoad: TButton;
    procedure btnSaveClick(Sender: TObject);
    procedure btnLoadClick(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation 

const  FNAME = 'Items.cln';

procedure TForm1.btnSaveClick(Sender: TObject);
begin
  CheckListBox1.SaveToFile(FNAME);
end;

procedure TForm1.btnLoadClick(Sender: TObject);
begin
  CheckListBox1.LoadFromFile(FNAME);
end;
...

Muestra:


Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita