1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
| unit UFRM_Main;
interface
uses
// ...... uses clauses
type TPanelCellValue = class
zBool : boolean;
zLabelContent : string;
zEditContent : string;
end;
type TAccItem = class
zsName : string;
zsTown : string;
end;
type TPanelCell = class(TPanel)
iLabel : TLabel;
iCheckBox : TCheckBox;
iEdit : TEdit;
Constructor Create (AOwner: TComponent);override;
protected
procedure SetData(const Value: TValue);override;
end;
type TPanelCol = class(TColumn)
protected
function CreateCellControl: TStyledControl;override;
end;
type TCheckBoxCell = class (TCheckBox)
end;
type
TForm3 = class(TForm)
Grid1: TGrid;
Cnx: TUniConnection;
QrAccList: TUniQuery;
procedure FormCreate(Sender: TObject);
procedure Grid1GetValue(Sender: TObject; const Col, Row: Integer;var Value: TValue);
procedure Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const [Ref] Bounds: TRectF; const Row: Integer;
const [Ref] Value: TValue; const State: TGridDrawStates);
private
{ Déclarations privées }
dftPanelCellValue : TPanelCellValue;
AccList : TList<TAccItem>;
public
{ Déclarations publiques }
end;
var
Form3: TForm3;
implementation
{$R *.fmx}
function TCol1.CreateCellControl: TStyledControl;
begin
Result := TCheckBoxCell.Create(self);
end;
function TPanelCol.CreateCellControl: TStyledControl;
begin
Result := TPanelCell.Create(self);
end;
Constructor TPanelCell.Create(Aowner: TComponent);
begin
inherited;
iLabel := TLabel.Create(self);
iLabel.Parent := self;
iLabel.Text := 'Test';
iCheckbox := TCheckBox.Create(self);
iCheckbox.Position.Y := 30;
iCheckBox.Parent := self;
iEdit := TEdit.Create(self);
iEdit.Parent := self;
iEdit.Position.Y := 60;
iEdit.Width := 200;
end;
procedure TForm3.FormCreate(Sender: TObject);
var i : integer;
begin
{$IFDEF MSWINDOWS}
cnx.Database := 'Path to the database';
{$ENDIF MSWINDOWS}
{$IFDEF Android}
cnx.Database := System.IOUtils.TPath.GetHomePath + System.IOUtils.TPath.DirectorySeparatorChar + 'databaseName';
{$ENDIF Android}
try
cnx.Connected := true;
QrAccList.Execute;
except
showmessage('could not open database');
end;
Grid1.AddObject(TPanelCol.Create(Grid1));
Grid1.Columns[0].Width := Grid1.Width;
Grid1.RowCount := 5000;
end;
procedure TForm3.Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const [Ref] Bounds: TRectF; const Row: Integer;
const [Ref] Value: TValue; const State: TGridDrawStates);
var tP : TPanelCell;
begin
try
Canvas.BeginScene() ;
tP := TPanelCell.Create(nil);
// tP.Parent := Column;
tP.Height := Form3.Grid1.RowHeight;
tP.Width := Column.Width;
// tP.Position.X := Bounds.Left ;
// tP.Position.Y := Bounds.Top ;}
tp.PaintTo(Canvas, Bounds);
Canvas.EndScene;
finally
// tp.Free;
end;
end;
procedure TForm3.Grid1GetValue(Sender: TObject; const Col, Row: Integer;
var Value: TValue);
var lVal : TPanelCellValue;
begin
if col = 0 then begin
lVal := TPanelCellValue.Create();
lVal.zLabelContent := inttostr(row);
TValue.Make(@lVal,TypeInfo(TPanelCellValue),Value);
end ;
end;
procedure TPanelCell.SetData(const Value: TValue) ;
var
lVal : TPanelCellValue;
begin
lVal := TPanelCellValue.Create();
Value.ExtractRawData(@lVal);
iLabel.Text := 'Row ' + lVal.zLabelContent;
iCheckBox.IsChecked := strtoint(lVal.zLabelContent) MOD 2 = 0;
iEdit.Text := 'Edit the row ' + lVal.zLabelContent;
end;
end. |
Partager