Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: CheckListBox : how to load/save easily with check states

331 views
Skip to first unread message

Remy Lebeau (TeamB)

unread,
Dec 19, 2007, 5:42:15 PM12/19/07
to

"Olivier Pons" <olivier.dot.pons...@ignore.this.fr> wrote in
message news:4769...@newsgroups.borland.com...

> Is there a way to save easily the strings of CheckListBox + the
> states (checked or not) ? And a way to load them and automatically
> restore the states for each string ?

TCheckListBox does not expose access to that functionality. You will have
to do it manually.


Gambit


Olivier Pons

unread,
Dec 19, 2007, 5:39:29 PM12/19/07
to
Is there a way to save easily the strings of CheckListBox + the states (checked or not) ?
And a way to load them and automatically restore the states for each string ?

--
Olivier Pons
http://olivier.pons.free.fr/

Rob Kennedy

unread,
Dec 19, 2007, 9:57:14 PM12/19/07
to
Olivier Pons wrote:
> Is there a way to save easily the strings of CheckListBox + the states
> (checked or not) ?

Yes. There are a few easy ways. That is, none of the solutions that
you'll have to write yourself should be particularly challenging.

> And a way to load them and automatically restore the states for each
> string ?

No. Nothing automatic.

--
Rob

Dan

unread,
Dec 20, 2007, 11:48:39 AM12/20/07
to
"Olivier Pons" <olivier.dot.pons...@ignore.this.fr> wrote in
message news:4769...@newsgroups.borland.com...

For some reason I can't find the CheckListBox component, but if the items in
it and it's state are public properties then Orpheus should be able to save
and restore it's state for you, all you do is add the properties to be
saved. But from what I've seen by the other responses it would look like
they are either not properties, or not Public. Well, you might as well go
ahead and check anyways.

- Dan

Remy Lebeau (TeamB)

unread,
Dec 20, 2007, 3:02:25 PM12/20/07
to

"Dan" <froze...@gmail.com> wrote in message
news:476a...@newsgroups.borland.com...

> For some reason I can't find the CheckListBox component

> if the items in it and it's state are public properties then Orpheus


> should be able to save and restore it's state for you

The Items property is a published TStrings, but the Checked[] property is
public instead. Assuming Orpheus uses RTTI to do its work, then it won't be
able to stream non-published properties.


Gambit


HeartWare

unread,
Dec 21, 2007, 7:53:09 AM12/21/07
to
On Dec 19, 11:39 pm, Olivier Pons
<olivier.dot.pons.at.gmaildot....@ignore.this.fr> wrote:

> Is there a way to save easily the strings of CheckListBox + the states (checked or not) ?
> And a way to load them and automatically restore the states for each string ?

The following (untested) CLASS HELPER should allow you to do it
directly on the CheckListBox variable. If you do not run at least
Delphi 2006, then you should be able to figure out how to do it
manually by looking at the code. Put the code below into a UNIT and
USE it in the form that contains the CheckListBox. Then just use
CheckListBox1.SaveStatesToFile('C:\STATES.DAT') to save the items +
their respective states to the file 'C:\STATES.DAT'.

TYPE
TCheckListBoxHelper = CLASS HELPER FOR TCheckListBox
PROCEDURE SaveStatesToStream(S : TStream);
PROCEDURE LoadStatesFromStream(S : TStream);
PROCEDURE SaveStatesToFile(CONST FileName :
STRING);
PROCEDURE LoadStatesFromFile(CONST
FileName : STRING);
END;

PROCEDURE TCheckListBoxHelper.SaveStatesToStream(S : TStream);
VAR
TXT : AnsiString;
I : INTEGER;

BEGIN
FOR I:=0 TO Items.Count-1 DO BEGIN
IF Checked[I] THEN TXT:='+' ELSE TXT:='-';
TXT:=TXT+Items[I]+#13#10;
S.Write(TXT[1],LENGTH(TXT))
END
END;

PROCEDURE TCheckListBoxHelper.LoadStatesFromStream(S : TStream);
VAR
TXT : AnsiString;
C : AnsiChar;
I : INTEGER;
CHK : BOOLEAN;

BEGIN
Items.Clear;
WHILE S.Position<S.Size DO BEGIN
TXT:='';
REPEAT
S.Read(C,SizeOf(C));
IF C=#13 THEN BEGIN
S.Read(C,SizeOf(C)); // Skip past LF character //
BREAK
END;
TXT:=TXT+C
UNTIL S.Position>=S.Size;
CHK:=(TXT[1]='+');
DELETE(TXT,1,1);
Checked[Items.Add(TXT)]:=CHK
END
END;

PROCEDURE TCheckListBoxHelper.SaveStatesToFile(CONST FileName :
STRING);
VAR
S : TStream;

BEGIN
S:=TFileStream.Create(FileName,fmCreate);
TRY
SaveStatesToStream(S)
FINALLY
FreeAndNIL(S)
END
END;

PROCEDURE TCheckListBoxHelper.LoadStatesFromFile(CONST FileName :
STRING);
VAR
S : TStream;

BEGIN
S:=TFileStream.Create(FileName,fmOpenRead);
TRY
LoadStatesFromStream(S)
FINALLY
FreeAndNIL(S)
END
END;

Olivier Pons

unread,
Dec 25, 2007, 3:45:36 PM12/25/07
to
Remy Lebeau (TeamB) a écrit :

That's what I thought so I was just wondering if someone has ever done such thing.
Anyway I'll do it on my own... sad.

0 new messages