dbadvgrid.getcellcolor / AddImageIdx

I'am using this code to place an image to various cells, But the cells with images always flickering

thanks for any help

procedure TForm1.DBAdvGrid2GetCellColor(Sender: TObject; ARow, ACol: Integer;
AState: TGridDrawState; ABrush: TBrush; AFont: TFont);

var verschleiert : boolean;
begin
verschleiert:=true;

if (ARow > 0) and (acol>0) then
if ((pos('Sa',dbadvgrid2.Columns[acol].Header)<>0) or (pos('So',dbadvgrid2.Columns[acol].Header)<>0)) then
begin
ABrush.Color:=clgray;
afont.Color:=clWhite;
end
else
if (length(dbadvgrid2.Columns[acol].Header)>17) then
begin
ABrush.Color:=clsilver;
afont.Color:=clWhite;
end
else
if (pos(dbadvgrid2.Cells[acol,arow],'USKHDWEBQFRO')<>0) and verschleiert then
begin
dbadvgrid2.AddImageIdx(acol, arow, 0, haCenter, vaCenter);
end
else
if dbadvgrid2.Cells[acol,arow]='U' then
begin
ABrush.Color:=clPurple;
afont.Color:=clPurple;
end
else
if dbadvgrid2.Cells[acol,arow]='S' then
begin
ABrush.Color:=clgreen;
afont.Color:=clgreen;
end
else .....

Your code is not good. You should not insert images from the OnGetCellColor event.
The OnGetCellColor event is triggered whenever a cell needs to be painted. When you use AddImageIdx() from this event, the AddImageIdx() causes a cell repaint, hence, it triggers OnGetCellColor again and you can get into an infinite loop. So, avoid calls that cause grid repains from OnGetCellColor()

Hello Bruno,
thank you for your fast response.
Is there another way to show cells with different field values for users with different rights.
For example:
user group 1: can see all different field values
user group 2: can see the same field(cell) only blank or another content (not colors, i use it for user group 1)

Do you mean different text?
If so, cell text can be dynamically customized with the event handler grid.OnGetDisplText

Yes, i do mean so.
i did tested grid.ongetdisplay but the application crashed. the grid.ongetcellcolor was active without AddImageIdx().

procedure TForm1.DBAdvGrid2GetDisplText(Sender: TObject; ACol, ARow: Integer;
var Value: string);
begin
if (pos(dbadvgrid2.Cells[acol,arow],'USKHDWEBQFRO')<>0) then
begin
value:=covertext;
end
else
value:='';
end;

Can you please provide more details, like what exact error message you got and if this error is happening in this OnGetDisplText() event etc... Without details, it is impossible to guess what exactly happens in your app.

They application crashed and closed without an error message.
The same effect shown with grid.ongethtmltemplate ...
The reason for it is if i use: ... dbadvgrid2.Cells[acol,arow] ... like showmessage(dbadvgrid2.Cells[acol,arow]) -> see my previous message.
Now i try to use field variable, but i don't know how precisely it is..

I'm sorry but I don't understand the full scope of what exactly you are doing.
To access the field variable, use dataset.FieldByName('myfieldname').DisplayText for example.