Hola.
Si te entendí bien podrías hacer algo similar a esto:
Código Delphi
[-]
...
procedure TForm1.FormCreate(Sender: TObject);
begin
unQuery.Close;
unQuery.SQL.Text := 'SELECT ID, NOMBREPUESTO FROM PUESTO';
unQuery.Open;
while not unQuery.Eof do
begin
CheckListBox1.AddItem( unQuery.FieldByName( 'NOMBREPUESTO' ).AsString,
TObject(unQuery.FieldByName ( 'ID' ).AsInteger ) );
unQuery.Next;
end;
unQuery.Close;
end;
procedure TForm1.ActualizarPuestos( const EmpID: Integer );
var
i : Integer;
begin
for i := 0 to CheckListBox1.Items.Count - 1 do
CheckListBox1.Checked[i] := False;
unQuery.Close;
unQuery.SQL.Clear;
unQuery.SQL.Add( 'SELECT P.ID AS PUESTOID FROM EMPLEADOS E' );
unQuery.SQL.Add( 'INNER JOIN ASIGNADOS A ON E.ID = A.EMPLEADO_ID' );
unQuery.SQL.Add( 'INNER JOIN PUESTOS P ON P.ID = A.PUESTO_ID' );
unQuery.SQL.Add( 'AND E.ID = :EMPID' );
unQuery.ParamByName( 'EMPID' ).AsInteger := EmpID;
unQuery.Open;
while not unQuery.Eof do
begin
i := CheckListBox1.Items.IndexOfObject(
TObject( unQuery.FieldByName( 'PUESTOID' ).AsInteger ) );
if i <> -1 then
CheckListBox1.Checked[i] := True;
unQuery.Next;
end;
end;
...
Llamada ejemplo:
Código Delphi
[-]
begin
ActualizarPuestos( SpinEdit1.Value );
...
De ese modo se carga una sola vez la totalidad de puestos en el CheckListBox y se marcan con un tilde los puestos que tiene asignados el empleado cuyo ID se le envía al procedimiento
ActualizarPuestos.
Espero haberte interpretado bien...
Saludos