Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   componente TstringGrid con panel de propiedades (https://www.clubdelphi.com/foros/showthread.php?t=96154)

juank1971 11-03-2023 22:38:00

componente TstringGrid con panel de propiedades
 
Hola quisiera hacer un componente que herede de TstringGrid, y arriba de este poner un panel o varios con algunas propiedades visuales para cambiar colores tipos de letras, filtrar, etc, pero no logro crear un componente que cree otro componente en el constructor.

Esta es la unit que tengo muy básica a ver si me ayudan quisiera que crear un Trectangle en el padre de el grid, y ponerlo en el top , como casi siempre tengo los grids en un contenedor TTabItem y este rectángulo quisiera saliera arriba del grid por tanto tendría el mismo padre que el grid.

A lo mejor surge otra idea, lo que si quisiera es crear un componente TstrinGrid, con paneles para propiedades y de ser posibles varios , por ejemplo un panel o Rectangulo para filtrar, otro para configurar columnas, otro para configurar tipos de letras tamaños y colores etc.

Código Delphi [-]
unit StringGridMy;

interface

uses
  System.SysUtils, System.Classes, FMX.Types, FMX.Controls,
  FMX.Controls.Presentation, FMX.ScrollBox, FMX.Grid,FMX.Objects,FMX.Grid.Style,FMX.Presentation.Factory,FMX.Presentation.Style,
  FMX.Layouts, System.UITypes,FMX.Graphics,FMX.StdCtrls;

type

  TStringGridMy= class(TStringGrid)
  private
    vRectMain: TRectangle;
  protected
    { Protected declarations }
  public
     property RectMain: TRectangle read vRectMain write vRectMain;
    constructor Create(AOwner: TComponent); override;
  published
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('ComponenteMy', [TStringGridMy]);
end;



constructor TStringGridMy.Create(AOwner: TComponent);
begin
  inherited  Create(AOwner);
  Height := 480;
  Width := 640;
 
 
    vRectMain := TRectangle.Create(self.parent);//aqui quisiera viera el padre del grid
    vRectMain.Parent := self.parent;
    vRectMain.Align := TAlignLayout.top;
    vRectMain.Width := Self.Width;
    vRectMain.Height := 50;
    vRectMain.bringtofront;
    vRectMain.Fill.Color := TAlphaColorRec.White;
    vRectMain.Fill.Kind := TBrushKind.Solid;
 

end;


initialization
  TPresentationProxyFactory.Current.Register(TStringGridMy, TControlType.Styled, TStyledPresentationProxy);

finalization
  TPresentationProxyFactory.Current.Unregister(TStringGridMy, TControlType.Styled, TStyledPresentationProxy);

históricamente hablando se que nunca he logrado entender bien a fondo el orden de construir y destruir los objetos en DELPHI, creo que por no entender bien esto he pasado tanto trabajo con la creación de los controles o componentes durante muchos años jeje.

juank1971 12-03-2023 20:17:47

buscando ayuda he seguido este link
de embarcadero https://docwiki.embarcadero.com/RADS...onent_(Delphi)

Y Aunque puedo con este enlace lo que quiero visualmente que es un componente que contenga un grid y un rectangulo arriba, pero no puedo ver las propiedades de los mismos , del grid ni del rectangulo.

seria bueno esto mismo para contener varios componentes en uno ,pero mostrando todas las propiedades de cada cual, para poder enlazarlas en tiempo de diseño

Neftali [Germán.Estévez] 14-03-2023 09:37:30

Yo en este caso (y tal vez me equivoco) optaría por deribar no de un TStringGrid, sino de un componente que te sirve de contenedor de ambos, por ejemplo un TRectangle o un TPanel.
Otra opción es generar un Frame con lo que necesitas y reaprovecharlo. Tal vez esta opción sea más sencilla si no estás "muy puesto" en el tema de diseño de componentes de FMX (que no es igual que en VCL).

Una prueba rápida:

Código Delphi [-]
unit uStringGridProps;

interface

uses
  System.SysUtils, System.Classes, FMX.Types, FMX.Controls, FMX.Objects, FMX.Grid,
  FMX.Grid.Style,FMX.Presentation.Factory,FMX.Presentation.Style;

type
  TStringGridProps = class(TRectangle)
  private
    stGrid: TStringGrid;
    RecProps, RecFiltro: TRectangle;
    FVisibleGrid: boolean;
    FVisibleProps: boolean;
    FVisibleFiltro: boolean;
    procedure SetVisibleFiltro(const Value: boolean);
    procedure SetVisibleProps(const Value: boolean);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Grid:TStringGrid read stGrid write stGrid;
    property VisibleGrid:boolean read FVisibleGrid;
    property VisibleProps:boolean read FVisibleProps write SetVisibleProps;
    property VisibleFiltro:boolean read FVisibleFiltro write SetVisibleFiltro;
  end;

procedure Register;

implementation

uses
  System.UITypes;

procedure Register;
begin
  RegisterComponents('Samples', [TStringGridProps]);
end;

{ TStringGridProps }

constructor TStringGridProps.Create(AOwner: TComponent);
begin
  inherited Create(Owner);

  // valores por defecto
  FVisibleGrid := True;
  FVisibleProps := False;
  FVisibleFiltro := False;


    // StringGrid
    stGrid := TStringGrid.Create(Self.Parent);
    stGrid.Name := 'stGrig';
    stGrid.Parent := Self.Parent;
    stGrid.Align := TAlignLayout.Client;
    // Rectangulo de prppiedades
    RecProps := TRectangle.Create(Self.Parent);
    RecProps.Name := 'RecProps';
    RecProps.Parent := Self.Parent;
    RecProps.Align := TAlignLayout.Top;
    // RecBtFirst.Stroke.Kind := Stroke.Kind.bkNone;
    RecProps.fill.Color := TAlphaColorRec.Darkgray;
    RecProps.Height := 80;
    RecProps.Tag := 1;
    // Rectangulo de filtro
    RecFiltro := TRectangle.Create(Self.Parent);
    RecFiltro.Name := 'RecFiltro';
    RecFiltro.Parent := Self.Parent;
    RecFiltro.Align := TAlignLayout.Top;
    // RecBtFirst.Stroke.Kind := Stroke.Kind.bkNone;
    RecFiltro.fill.Color := TAlphaColorRec.Darkgray;
    RecFiltro.Height := 80;
    RecFiltro.Tag := 1;

  Self.Repaint;

end;

destructor TStringGridProps.Destroy;
begin

  inherited;
end;


procedure TStringGridProps.SetVisibleFiltro(const Value: boolean);
begin
  FVisibleFiltro := Value;
  RecFiltro.Visible := FVisibleFiltro;
  Repaint;
end;

procedure TStringGridProps.SetVisibleProps(const Value: boolean);
begin
  FVisibleProps := Value;
  RecFiltro.Visible := FVisibleProps;
  Repaint;
end;

initialization
  TPresentationProxyFactory.Current.Register(TStringGridProps, TControlType.Styled, TStyledPresentationProxy);

finalization
  TPresentationProxyFactory.Current.Unregister(TStringGridProps, TControlType.Styled, TStyledPresentationProxy);

end.

juank1971 14-03-2023 14:56:31

gracias voy probando


La franja horaria es GMT +2. Ahora son las 00:40:58.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi