Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Crear un DbGrid en una TTabSheet (https://www.clubdelphi.com/foros/showthread.php?t=46021)

GerTorresM 21-07-2007 00:00:23

Crear un DbGrid en una TTabSheet
 
Estoy intentando crear un DBGrid dentro una pestaña de un PageControl, para lo cual estoy empleando el siguiente código

Código Delphi [-]
 
PCInformacion:= TPageControl.Create(Self);
with PCInformacion do
begin
  Parent:= Form1; 
  Align:= AlClient;
end;
Hoja1:=TTabSheet.Create(PCInformacion);
with Hoja1 do
begin
  PageControl:= PCInformacion;
  Caption:= 'Hola Mundo';
  DTPFecha:= TDateTimePicker.Create(Self); 
  DBGDatos:= TDBGrid.Create(Self);
  DataSource:= TDataSource.Create(Self);
  DTPFecha.Parent:= Hoja1;
  DBGDatos.Parent:= Pagecontrol.Activepage;
end;

pero al intentar correr la apliación me envía el siguiente mensaje

Incompatibles types TWidgetControl And TTabSheet, al comentariar la línea donde fijo de parent del DBGrid, corre, pero no me dibuja el compnente, no se como puede remediar el error o cual sintaxis a emplear

dec 21-07-2007 02:02:47

Hola,

¿De dónde se supone que sale "TWidgetControl"?

ariefez 21-07-2007 19:39:07

No se porque sale ese error pero ami si q me corre esa prsion de codigo, esta es la forma en la q corre

Código Delphi [-]
procedure TForm2.FormCreate(Sender: TObject);
var
  PCInformacion: TPageControl;
  Hoja1:TTabSheet;
begin
  PCInformacion:= TPageControl.Create(Self);
  with PCInformacion do
  begin
    Parent:= Self;
    Align:= AlClient;
  end;
  Hoja1:=TTabSheet.Create(PCInformacion);
  with Hoja1 do
  begin
    PageControl:= PCInformacion;
    Caption:= 'Hola Mundo';
    DBGDatos.Parent:= Hoja1;
  end;
end;


como no mencionas de q tipo es Hoja1 supuse q era TTabSheet :D

GerTorresM 21-07-2007 22:52:55

Codigo Completo
 
Como tal vez o fui claro en la pregunta, me permito enviar la totalidad del código (no es muy largo por fortuna), y para mayor información estoy trabajando en Delphi 6 Enterprise.

el código es el siguiente

unit UFormulario;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QComCtrls,DB, ComCtrls, QDBGrids;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
PCInformacion : TPageControl;
DTPFecha : TDateTimePicker;
Hoja1, Hoja2: TTabSheet;
DataSource : TDataSource;
DBGDatos: TDBGrid;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
PCInformacion:= TPageControl.Create(Self);
with PCInformacion do
begin
Parent:= Form1;
Align:= AlClient;
end;
Hoja1:=TTabSheet.Create(PCInformacion);
with Hoja1 do
begin
PageControl:= PCInformacion;
Caption:= 'Hola Mundo';
DTPFecha:= TDateTimePicker.Create(Self);
DBGDatos:= TDBGrid.Create(Self);
DataSource:= TDataSource.Create(Self);
DTPFecha.Parent:= Hoja1;
DBGDatos.Parent := Hoja1; // aqui es donde sale el error mencionado en la pregunta
end;
Hoja2:= TTabSheet.Create(PCInformacion);
with Hoja2 do
begin
PageControl:= PCInformacion;
Caption:= 'Hola Mundo en la Hoja 2';
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DTPFecha.Destroy;
Hoja1.Destroy;
Hoja2.Destroy;
PCInformacion.Destroy;
end;
end.

Gracías de antemano por su tiempo y colaboración

ariefez 22-07-2007 16:09:04

Pues no le veo utilidad a las unidades QComCtrls, QDBGrids, o almenos a mi no me las reconoce :rolleyes:, en vez de eso use ComCtrls, DBGrids y corre normal, te pego el codigo sin esas unidades. una cosa mas para liberar, se usa la rutina Free o FreeAndNil... un consejo al escribir tu mensaje resalta tu codigo con el boton Resaltar sintaxis delphi y quedara mas legible, suerte que existe Jedi Code Format, sino, no seria legible tu codigo.

Código Delphi [-]
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, DB, DBGrids;

type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2:      TForm2;
  PCInformacion: TPageControl;
  DTPFecha:   TDateTimePicker;
  Hoja1, Hoja2: TTabSheet;
  DataSource: TDataSource;
  DBGDatos:   TDBGrid;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
  PCInformacion := TPageControl.Create(Self);
  with PCInformacion do
  begin
    Parent := Form2;
    Align  := AlClient;
  end;
  Hoja1 := TTabSheet.Create(PCInformacion);
  with Hoja1 do
  begin
    PageControl := PCInformacion;
    Caption     := 'Hola Mundo';
    DTPFecha    := TDateTimePicker.Create(Self);
    DBGDatos    := TDBGrid.Create(Self);
    DataSource  := TDataSource.Create(Self);
    DTPFecha.Parent := Hoja1;
    DBGDatos.Parent := Hoja1; // aqui es donde sale el error mencionado en la pregunta
  end;
  Hoja2 := TTabSheet.Create(PCInformacion);
  with Hoja2 do
  begin
    PageControl := PCInformacion;
    Caption     := 'Hola Mundo en la Hoja 2';
  end;
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  DTPFecha.Free;
  Hoja1.Free;
  Hoja2.Free;
  PCInformacion.Free;
end;

end.

Una cosa mas al crear los controles, debes darles las coordenadas y dimensiones sino no los vaz a ver o van estar desordenados

GerTorresM 22-07-2007 21:50:34

Mejor Imposible
 
Les agradezco a todos su colaboración, me agrada muchisimo poder contar con gente con ustedes y con un sitio tan especilizado y organizado como el club.


Gracías:)


La franja horaria es GMT +2. Ahora son las 03:57:56.

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