In the TGrid registry I have a BLOB SQL column that I display in TGrid as ImageStyle. Everything works fine, there are no errors.
However, in TGrid I need to change the color of the rows. Selected row – color1, remaining rows – color2. And this is where my problems begin. I couldn’t find a simple way to solve my problem, so I started adding lines of code. first I removed problems with coloring, then problems arose with photos not being visible in the registry. Currently, I have the effect I wanted (there are colors and photos), but after scrolling down the lines, the program crashes with the error “Access violation at address 00F3C2D7 in module ‘Katalog_klockow_21.exe’. Read of address 0000000C.”.
I tried debugging, but I am unable to locate which line the error occurs on. Event
OnDrawColumnCell causes it to run as soon as you hover the cursor over the slider, so I can’t even move it.
I would like to point out that as long as I did not modify the color, the registry worked without errors and the photos were displayed correctly.
I am asking for advice on how I should deal with the seemingly simple color change.
My code:
private
{ Private declarations }
FSelectedRow: Integer;
procedure TZ.RejestrCellClick(const Column: TColumn; const Row: Integer);
begin
Rejestr.SelectRow(Row);
FSelectedRow := Row;
Rejestr.Repaint; // Odśwież grid, aby ponownie narysować komórki
end;
procedure TZ.RejestrDrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF; const Row: Integer;
const Value: TValue; const State: TGridDrawStates);
begin
UstawWygladRejestru (Sender, Canvas, Column, Bounds, Row, Value,State, FSelectedRow);
end;
procedure TZ.UstawWygladRejestru (Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF; const Row: Integer;
const Value: TValue; const State: TGridDrawStates; Wiersz: Integer);
begin
//exit;
var Bitmap: TBitmap;
begin
if Row = Wiersz then
Canvas.Fill.Color := TAlphaColors.Bisque
else
Canvas.Fill.Color := TAlphaColors.Beige;
Canvas.FillRect(Bounds, 0, 0, [], 1);
if Column is TImageColumn then
begin
if Value.IsType<TBitmap> then
begin
Bitmap := Value.AsType<TBitmap>;
Canvas.DrawBitmap(Bitmap, RectF(0, 0, Bounds.Width, Bounds.Height),
Bounds, 1, True);
end;
end
else
begin
Canvas.Fill.Color := TAlphaColors.Black;
Canvas.FillText(Bounds, Value.ToString, False, 1, [], TTextAlign.Leading, TTextAlign.Center);
end;
end;
i
So far, I’ve been focusing on finding the simplest solution. The moment I found it, it turned out that I had the “Acces Violaion…” error.
Woj Tas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4