这是一个TStringGrid
包含 2TStringColumn
列、一个按钮和一个编辑框的组件的表单。单击按钮应更改一个单元格的内容及其背景颜色、列的颜色和编辑框的颜色。单元格文本已正确更新和格式化,编辑框的颜色已更改,但单元格的颜色没有改变,列的颜色也没有改变。
我相信我已经遵循了 Ray Konopka 和 Mike Sutton 之前的所有提示......谁能告诉我为什么这段代码的某些部分不起作用?
我知道代码可能无法与更高版本的 FireMonkey 一起编译。
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Grid, FMX.Layouts, FMX.Objects,
FMX.Edit;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
StringGrid1: TStringGrid;
StringColumn1: TStringColumn;
StringColumn2: TStringColumn;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
rect: TRectangle;
cell: TTextCell;
text: string;
begin
// Select a cell in column 1
cell:= stringColumn1.CellControlByRow(3) as TTextCell;
// Enter some text in cell
text:= 'hello sailor';
cell.TextAlign:= TTextAlign.taCenter;
cell.Text:= text; // works fine
// Change cell background color
rect:= cell.FindStyleResource('background') as TRectangle;
if rect <> nil then
rect.Fill.Color:= claRed; // does nothing
// Change color of all cells in grid
rect:= stringGrid1.FindStyleResource('background') as TRectangle;
if rect <> nil then
rect.Fill.Color:= claBisque; // works fine
// Change color of all cells in column 2
rect:= stringColumn2.FindStyleResource('background') as TRectangle;
if rect <> nil then
rect.Fill.Color:= claGreen; // does nothing
// Change background color of edit box
rect:= edit1.FindStyleResource('background') as TRectangle;
if rect <> nil then
rect.Fill.Color:= claBlue; // works fine
end;
end.