Nur sinngemäß, da ich gerade kein Delphi offen habe, geht bestimmt auch einfacher:
Delphi-Quellcode:
type
TLBColor=class
public
Color:TColor;
end;
//Item zur Liste hinzufügen:
procedure TForm1.Button1Click(Sender: TObject);
var t:TLBColor;
begin
t:=TLBColor.Create;
t.Color:=clWhite;
Listbox1.AddItem('
foo',t);
end;
//in deiner Prüffunktion
while i < Form1.ListBox1.Count
do begin
userId := sqlst.query('
select id from user_ where username = ''
'+Form1.listbox1.Items[i]+'
''
');
//user not found
if userId = '
'
then //Change Color of current line - cLYellow
TLBColor(Listbox1.Items.Objects(i)).Color:=clRed;
i := i + 1;
end;
procedure TForm1.ListBox1DrawItem
(Control: TWinControl;
Index: Integer;
Rect: TRect; State: TOwnerDrawState) ;
var
myColor: TColor;
myBrush: TBrush;
begin
myBrush := TBrush.Create;
with (Control
as TListBox).Canvas
do
begin
myColor := TLBColor(Listbox1.Items.Objects(
index)).Color;
myBrush.Style := bsSolid;
myBrush.Color := myColor;
Windows.FillRect(
handle, Rect, myBrush.Handle) ;
Brush.Style := bsClear;
TextOut(Rect.Left, Rect.Top,
(Control
as TListBox).Items[
Index]) ;
MyBrush.Free;
end;
end;