Всем привет накидал тут пару простых компонентов, сильно не ругайте сами компоненты, это просто для примера самой задачи
Дальше вопрос, как к "типа табличному" компоненту прицепить чтото чтоб его в "bind visualy" было видно и оно заполнялось как таблица
вот из моего примера как задать колонкам например поля таблицы а строкам значения...
вот листинг
unit RR.TextPanel;
interface
uses
System.Classes,
System.SysUtils,
FMX.Objects,
FMX.Types,
FMX.Graphics;
type
TCustomTextPanel=class(TRectangle)
protected
FTextOutline : TText;
procedure SetText(value:string);
function GetText:string;
procedure SetSettings(value:TTextSettings);
function GetSettings:TTextSettings;
function GetTextMargins:TBounds;
public
constructor Create(AOwner:TComponent);override;
property Text:string read GetText write SetText;
property TextSettings:TTextSettings read GetSettings write SetSettings;
property TextMargins:TBounds read GetTextMargins;
destructor Destroy;override;
end;
TTextPanel = class (TCustomTextPanel)
published
property Text;
property TextSettings;
property TextMargins;
end;
implementation
constructor TCustomTextPanel.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
Parent:=TFmxObject(AOwner);
Stroke.Kind:=TBrushKind.None;
FTextOutline:=TText.Create(Self);
FTextOutline.Parent:=Self;
FTextOutline.Align:=TAlignLayout.Client;
FTextOutline.Text:='text';
FTextOutline.TextSettings.WordWrap:=True;
FTextOutline.TextSettings.Font.Family:='Arial';
FTextOutline.HitTest:=False;
end;
procedure TCustomTextPanel.SetText(value:string);
begin
FTextOutline.Text:=value;
end;
function TCustomTextPanel.GetText:string;
begin
Result:=FTextOutline.Text;
end;
procedure TCustomTextPanel.SetSettings(value:TTextSettings);
begin
FTextOutline.TextSettings.Assign(value);
end;
function TCustomTextPanel.GetSettings:TTextSettings;
begin
Result:=FTextOutline.TextSettings;
end;
function TCustomTextPanel.GetTextMargins:TBounds;
begin
Result:=FTextOutline.Margins;
end;
destructor TCustomTextPanel.Destroy;
begin
FreeAndNil(FTextOutline);
inherited Destroy;
end;
end.
unit RR.SimpleGrid;
interface
uses
System.Classes,
System.SysUtils,
System.UITypes,
FMX.Objects,
FMX.Types,
FMX.Graphics,
RR.TextPanel;
type
TColScaleMode=(csmNone,csmDominant,csmEqual);
TCustomSimpleGrid = class;
TSimpleGridCustomRow = class(TRectangle)
protected
FCells : array of TTextPanel;
FGrid : TCustomSimpleGrid;
function GetCellItem(Index: Integer):TTextPanel;
procedure SetColCount(AColCount:integer);
public
constructor Create(AOwner:TComponent); override;
property Cell[Index: Integer]: TTextPanel read GetCellItem;
destructor Destroy; override;
end;
TCustomSimpleGrid = class(TRectangle)
protected
FRows : array of TSimpleGridCustomRow;
FColCount : Integer;
FScaledCol : Integer;
FColScaleMode : TColScaleMode;
FGridColor : TAlphaColor;
FDefaultRowHeight : integer;
function GetCell(X,Y:integer):TTextPanel;
procedure Resize; override;
procedure SetColCount(Value:integer);
procedure SetColScaleMode(Value:TColScaleMode);
function GetCellValue(X,Y:integer):string;
procedure SetCellValue(X,Y:integer;Value:string);
function GetRowCount:integer;
procedure SetRowCount(Value:integer);
procedure SetDefaultRowHeight(Value:integer);
procedure SetGridColor(Value:TAlphaColor);
public
constructor Create(AOwner:TComponent);override;
property Cell[X,Y:integer]:TTextPanel read GetCell;
property CellValues[X,Y:integer]:string read GetCellValue write SetCellValue;
property ColCount:integer read FColCount write SetColCount;
property RowCount:integer read GetRowCount write SetRowCount;
property ColScaleMode:TColScaleMode read FColScaleMode write SetColScaleMode;
property ScaledCow:integer read FScaledCol write FScaledCol;
property GridColor:TAlphaColor read FGridColor write SetGridColor;
property DefaultRowHeight:integer read FDefaultRowHeight write SetDefaultRowHeight;
destructor Destroy; override;
end;
TSimpleGrid = class(TCustomSimpleGrid)
published
property RowCount default 2;
property ColCount default 2;
property ColScaleMode;
property ScaledCow;
property GridColor default TAlphaColorRec.Gray;
property DefaultRowHeight default 22;
end;
implementation
constructor TSimpleGridCustomRow.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
Parent:=TFmxObject(AOwner);
ClipChildren:=True;
Fill.Kind:=TBrushKind.None;
end;
procedure TSimpleGridCustomRow.SetColCount(AColCount:integer);
var
OldColCount,i:integer;
X:single;
begin
OldColCount:=Length(FCells);
X:=0;
if AColCount>OldColCount then
begin
SetLength(FCells,AColCount);
for i := OldColCount to High(FCells) do
begin
FCells[i]:=TTextPanel.Create(Self);
if i>0 then
begin
X:=FCells[i-1].Width+FCells[i-1].Position.X+1;
FCells[i].Margins.Left:=1;
end;
FCells[i].Position.X:=X;
FCells[i].Align:=TAlignLayout.Left;
FCells[i].Fill.Color:=FGrid.FGridColor;
end
end else
if AColCount<OldColCount then
begin
for i := High(FCells) downto AColCount do
begin
FCells[i].Parent:=nil;
FreeAndNil(FCells[i]);
end;
SetLength(FCells,AColCount);
end;
end;
function TSimpleGridCustomRow.GetCellItem(Index: Integer):TTextPanel;
begin
if (Index>=0) and (Index < Length(FCells)) then
Result:=FCells[Index]
else
Result := nil;
end;
destructor TSimpleGridCustomRow.Destroy;
begin
SetColCount(0);
inherited;
end;
constructor TCustomSimpleGrid.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
Parent:=TFmxObject(AOwner);
Stroke.Kind:=TBrushKind.None;
ClipChildren:=True;
Fill.Color:=TAlphaColorRec.Black;
FColScaleMode:=csmDominant;
FScaledCol:=0;
FDefaultRowHeight:=22;
FGridColor:=TAlphaColorRec.White;
Resize;
end;
function TCustomSimpleGrid.GetCell(X,Y:integer):TTextPanel;
begin
Result:=FRows[Y].GetCellItem(X);
end;
function TCustomSimpleGrid.GetCellValue(X,Y:integer):string;
begin
Result:=FRows[Y].GetCellItem(X).Text;
end;
procedure TCustomSimpleGrid.SetCellValue(X,Y:integer;Value:string);
begin
FRows[Y].GetCellItem(X).Text:=Value;
end;
procedure TCustomSimpleGrid.SetColCount(Value:integer);
var
Ri:integer;
begin
if Length(FRows)>0 then
for Ri := 0 to High(FRows) do
FRows[Ri].SetColCount(Value);
FColCount:=Value;
Resize;
end;
function TCustomSimpleGrid.GetRowCount:integer;
begin
Result:=Length(FRows);
end;
procedure TCustomSimpleGrid.SetRowCount(Value:integer);
var
OldRowCount,i:integer;
begin
OldRowCount:=Length(FRows);
if Value>Length(FRows) then
begin
SetLength(FRows,Value);
for i := OldRowCount to High(FRows) do
begin
FRows[i]:=TSimpleGridCustomRow.Create(Self);
FRows[i].FGrid:=Self;
FRows[i].SetColCount(FColCount);
FRows[i].Margins.Top:=1;
FRows[i].Margins.Left:=1;
FRows[i].Margins.Bottom:=1;
FRows[i].Margins.Right:=1;
if i>0 then
FRows[i].Position.Y:=FRows[i-1].Position.Y+FRows[i-1].Height+3;
FRows[i].Align:=TAlignLayout.Top;
end;
end;
Resize;
end;
procedure TCustomSimpleGrid.SetDefaultRowHeight(Value:integer);
begin
FDefaultRowHeight:=Value;
Resize;
end;
procedure TCustomSimpleGrid.Resize;
function GetDomColW:single;
var
i:integer;
begin
Result:=0;
for i := 0 to FColCount-1 do
if i<>FScaledCol then
Result:=Result+FRows[0].FCells[i].Width;
Result:=FRows[0].Width-Result-1;
end;
var
Y,X:integer;
mW,eW,gH:single;
begin
gH:=FDefaultRowHeight;
if (Length(FRows)>0) and (FColCount>0) then
begin
gH:=0;
mW:=GetDomColW;
eW:=(Width-FColCount-1)/FColCount;
for Y :=0 to High(FRows) do
begin
if FColCount=1 then
FRows[Y].FCells[X].Width:=FRows[y].Width else
case FColScaleMode of
csmDominant:
FRows[Y].FCells[FScaledCol].Width:=mW;
csmEqual:
for x := 0 to High(FRows[Y].FCells) do
FRows[Y].FCells[x].Width:=eW;
end;
FRows[Y].Height:=FDefaultRowHeight;
gH:=gH+FRows[Y].Height+2;
end;
end;
Height:=gH;
inherited Resize;
end;
procedure TCustomSimpleGrid.SetColScaleMode(Value:TColScaleMode);
begin
FColScaleMode:=Value;
Resize;
end;
procedure TCustomSimpleGrid.SetGridColor(Value:TAlphaColor);
var
X,Y:integer;
begin
for Y := 0 to High(FRows) do
for X := 0 to FColCount-1 do
FRows[Y].FCells[X].Fill.Color:=Value;
FGridColor:=Value;
end;
destructor TCustomSimpleGrid.Destroy;
begin
SetRowCount(0);
inherited;
end;
end.
Вопрос
tromani
Всем привет накидал тут пару простых компонентов, сильно не ругайте сами компоненты, это просто для примера самой задачи
Дальше вопрос, как к "типа табличному" компоненту прицепить чтото чтоб его в "bind visualy" было видно и оно заполнялось как таблица
вот из моего примера как задать колонкам например поля таблицы а строкам значения...
вот листинг
unit RR.TextPanel; interface uses System.Classes, System.SysUtils, FMX.Objects, FMX.Types, FMX.Graphics; type TCustomTextPanel=class(TRectangle) protected FTextOutline : TText; procedure SetText(value:string); function GetText:string; procedure SetSettings(value:TTextSettings); function GetSettings:TTextSettings; function GetTextMargins:TBounds; public constructor Create(AOwner:TComponent);override; property Text:string read GetText write SetText; property TextSettings:TTextSettings read GetSettings write SetSettings; property TextMargins:TBounds read GetTextMargins; destructor Destroy;override; end; TTextPanel = class (TCustomTextPanel) published property Text; property TextSettings; property TextMargins; end; implementation constructor TCustomTextPanel.Create(AOwner:TComponent); begin inherited Create(AOwner); Parent:=TFmxObject(AOwner); Stroke.Kind:=TBrushKind.None; FTextOutline:=TText.Create(Self); FTextOutline.Parent:=Self; FTextOutline.Align:=TAlignLayout.Client; FTextOutline.Text:='text'; FTextOutline.TextSettings.WordWrap:=True; FTextOutline.TextSettings.Font.Family:='Arial'; FTextOutline.HitTest:=False; end; procedure TCustomTextPanel.SetText(value:string); begin FTextOutline.Text:=value; end; function TCustomTextPanel.GetText:string; begin Result:=FTextOutline.Text; end; procedure TCustomTextPanel.SetSettings(value:TTextSettings); begin FTextOutline.TextSettings.Assign(value); end; function TCustomTextPanel.GetSettings:TTextSettings; begin Result:=FTextOutline.TextSettings; end; function TCustomTextPanel.GetTextMargins:TBounds; begin Result:=FTextOutline.Margins; end; destructor TCustomTextPanel.Destroy; begin FreeAndNil(FTextOutline); inherited Destroy; end; end.unit RR.SimpleGrid; interface uses System.Classes, System.SysUtils, System.UITypes, FMX.Objects, FMX.Types, FMX.Graphics, RR.TextPanel; type TColScaleMode=(csmNone,csmDominant,csmEqual); TCustomSimpleGrid = class; TSimpleGridCustomRow = class(TRectangle) protected FCells : array of TTextPanel; FGrid : TCustomSimpleGrid; function GetCellItem(Index: Integer):TTextPanel; procedure SetColCount(AColCount:integer); public constructor Create(AOwner:TComponent); override; property Cell[Index: Integer]: TTextPanel read GetCellItem; destructor Destroy; override; end; TCustomSimpleGrid = class(TRectangle) protected FRows : array of TSimpleGridCustomRow; FColCount : Integer; FScaledCol : Integer; FColScaleMode : TColScaleMode; FGridColor : TAlphaColor; FDefaultRowHeight : integer; function GetCell(X,Y:integer):TTextPanel; procedure Resize; override; procedure SetColCount(Value:integer); procedure SetColScaleMode(Value:TColScaleMode); function GetCellValue(X,Y:integer):string; procedure SetCellValue(X,Y:integer;Value:string); function GetRowCount:integer; procedure SetRowCount(Value:integer); procedure SetDefaultRowHeight(Value:integer); procedure SetGridColor(Value:TAlphaColor); public constructor Create(AOwner:TComponent);override; property Cell[X,Y:integer]:TTextPanel read GetCell; property CellValues[X,Y:integer]:string read GetCellValue write SetCellValue; property ColCount:integer read FColCount write SetColCount; property RowCount:integer read GetRowCount write SetRowCount; property ColScaleMode:TColScaleMode read FColScaleMode write SetColScaleMode; property ScaledCow:integer read FScaledCol write FScaledCol; property GridColor:TAlphaColor read FGridColor write SetGridColor; property DefaultRowHeight:integer read FDefaultRowHeight write SetDefaultRowHeight; destructor Destroy; override; end; TSimpleGrid = class(TCustomSimpleGrid) published property RowCount default 2; property ColCount default 2; property ColScaleMode; property ScaledCow; property GridColor default TAlphaColorRec.Gray; property DefaultRowHeight default 22; end; implementation constructor TSimpleGridCustomRow.Create(AOwner:TComponent); begin inherited Create(AOwner); Parent:=TFmxObject(AOwner); ClipChildren:=True; Fill.Kind:=TBrushKind.None; end; procedure TSimpleGridCustomRow.SetColCount(AColCount:integer); var OldColCount,i:integer; X:single; begin OldColCount:=Length(FCells); X:=0; if AColCount>OldColCount then begin SetLength(FCells,AColCount); for i := OldColCount to High(FCells) do begin FCells[i]:=TTextPanel.Create(Self); if i>0 then begin X:=FCells[i-1].Width+FCells[i-1].Position.X+1; FCells[i].Margins.Left:=1; end; FCells[i].Position.X:=X; FCells[i].Align:=TAlignLayout.Left; FCells[i].Fill.Color:=FGrid.FGridColor; end end else if AColCount<OldColCount then begin for i := High(FCells) downto AColCount do begin FCells[i].Parent:=nil; FreeAndNil(FCells[i]); end; SetLength(FCells,AColCount); end; end; function TSimpleGridCustomRow.GetCellItem(Index: Integer):TTextPanel; begin if (Index>=0) and (Index < Length(FCells)) then Result:=FCells[Index] else Result := nil; end; destructor TSimpleGridCustomRow.Destroy; begin SetColCount(0); inherited; end; constructor TCustomSimpleGrid.Create(AOwner:TComponent); begin inherited Create(AOwner); Parent:=TFmxObject(AOwner); Stroke.Kind:=TBrushKind.None; ClipChildren:=True; Fill.Color:=TAlphaColorRec.Black; FColScaleMode:=csmDominant; FScaledCol:=0; FDefaultRowHeight:=22; FGridColor:=TAlphaColorRec.White; Resize; end; function TCustomSimpleGrid.GetCell(X,Y:integer):TTextPanel; begin Result:=FRows[Y].GetCellItem(X); end; function TCustomSimpleGrid.GetCellValue(X,Y:integer):string; begin Result:=FRows[Y].GetCellItem(X).Text; end; procedure TCustomSimpleGrid.SetCellValue(X,Y:integer;Value:string); begin FRows[Y].GetCellItem(X).Text:=Value; end; procedure TCustomSimpleGrid.SetColCount(Value:integer); var Ri:integer; begin if Length(FRows)>0 then for Ri := 0 to High(FRows) do FRows[Ri].SetColCount(Value); FColCount:=Value; Resize; end; function TCustomSimpleGrid.GetRowCount:integer; begin Result:=Length(FRows); end; procedure TCustomSimpleGrid.SetRowCount(Value:integer); var OldRowCount,i:integer; begin OldRowCount:=Length(FRows); if Value>Length(FRows) then begin SetLength(FRows,Value); for i := OldRowCount to High(FRows) do begin FRows[i]:=TSimpleGridCustomRow.Create(Self); FRows[i].FGrid:=Self; FRows[i].SetColCount(FColCount); FRows[i].Margins.Top:=1; FRows[i].Margins.Left:=1; FRows[i].Margins.Bottom:=1; FRows[i].Margins.Right:=1; if i>0 then FRows[i].Position.Y:=FRows[i-1].Position.Y+FRows[i-1].Height+3; FRows[i].Align:=TAlignLayout.Top; end; end; Resize; end; procedure TCustomSimpleGrid.SetDefaultRowHeight(Value:integer); begin FDefaultRowHeight:=Value; Resize; end; procedure TCustomSimpleGrid.Resize; function GetDomColW:single; var i:integer; begin Result:=0; for i := 0 to FColCount-1 do if i<>FScaledCol then Result:=Result+FRows[0].FCells[i].Width; Result:=FRows[0].Width-Result-1; end; var Y,X:integer; mW,eW,gH:single; begin gH:=FDefaultRowHeight; if (Length(FRows)>0) and (FColCount>0) then begin gH:=0; mW:=GetDomColW; eW:=(Width-FColCount-1)/FColCount; for Y :=0 to High(FRows) do begin if FColCount=1 then FRows[Y].FCells[X].Width:=FRows[y].Width else case FColScaleMode of csmDominant: FRows[Y].FCells[FScaledCol].Width:=mW; csmEqual: for x := 0 to High(FRows[Y].FCells) do FRows[Y].FCells[x].Width:=eW; end; FRows[Y].Height:=FDefaultRowHeight; gH:=gH+FRows[Y].Height+2; end; end; Height:=gH; inherited Resize; end; procedure TCustomSimpleGrid.SetColScaleMode(Value:TColScaleMode); begin FColScaleMode:=Value; Resize; end; procedure TCustomSimpleGrid.SetGridColor(Value:TAlphaColor); var X,Y:integer; begin for Y := 0 to High(FRows) do for X := 0 to FColCount-1 do FRows[Y].FCells[X].Fill.Color:=Value; FGridColor:=Value; end; destructor TCustomSimpleGrid.Destroy; begin SetRowCount(0); inherited; end; end.в общем было б интересно
src.zip
0 ответов на этот вопрос
Рекомендуемые сообщения
Присоединяйтесь к обсуждению
Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.