There is no automated way I know of. I would serialize a list manually using
Name Value Pair like this:

function SerializeCheckList(chklist: TCheckListBox): String;
var
  lst: TStringList;
  x: Integer;
begin
  lst := TStringList.Create;
  try
    for x := 0 to chklist.Items.Count - 1 do
      lst.Add(chklist.Items[x] + '=' + BoolToStr(chklist.Checked[x]));
    Result := lst.CommaText;
  finally
    lst.Free;
  end;
end;

procedure DeserializeCheckList(const sData: String; chklist: TCheckListBox);
var
  lst: TStringList;
  x, y: Integer;
begin
  lst := TStringList.Create;
  chklist.CheckAll(cbUnchecked);
  try
    lst.CommaText := sData;
    for x := 0 to lst.Count - 1 do
    begin
      y := chklist.Items.IndexOf(lst.Names[x]);
      if y < 0 then
        Continue;
      chklist.Checked[y] := StrToBool(lst.ValueFromIndex[x]);
    end;
  finally
    lst.Free;
  end;
end;

This code does assume the values in the list are not duplicated.

On Thu, Apr 14, 2011 at 4:58 PM, Stephen Posey
<stephenlpo...@earthlink.net>wrote:

> You can treat the check states effectively as an array of booleans. Is the
> number of items in the list fixed? Do the values in the database need to be
> human readable?
>
> Stephen Posey
> stephenlpo...@earthlink.net
>
>
> -----Original Message-----
> >From: SoftTech <mi...@softtechks.com>
> >Sent: Apr 14, 2011 4:54 PM
> >To: Delphi - Talk <delphi-talk@elists.org>
> >Subject: Anyone know how to store the values of a TCheckListBox into a
> database field?
> >
> >Greetings,
> >
> >I need to store the checked values for a TCheckListBox into a database
> field
> >and retrieve it.
> >
> >Anyone have tips on how to do it?
> >
> >Thanks,
> >Mike
> >
> >__________________________________________________
> >Delphi-Talk mailing list -> Delphi-Talk@elists.org
> >http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk
>
> __________________________________________________
> Delphi-Talk mailing list -> Delphi-Talk@elists.org
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk
>
__________________________________________________
Delphi-Talk mailing list -> Delphi-Talk@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

Reply via email to