![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Buscar | Temas de Hoy | Marcar Foros Como Leídos |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
|
|
#1
|
|||
|
|||
|
Buenas, al final he optado por crear el dataset a mano. No es lo que me hubiera gustado, que para eso existen los componentes graficos, pero funciona:
======================= unit WinFormU; interface uses System.Drawing, System.Collections, System.ComponentModel, System.Windows.Forms, System.Data, System.Globalization, Borland.Data.Provider, DataSetU; type TWinForm = class(System.Windows.Forms.Form) {$REGION 'Designer Managed Code'} strict private /// <summary> /// Required designer variable. /// </summary> Components: System.ComponentModel.Container; DataGrid1: System.Windows.Forms.DataGrid; /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> procedure InitializeComponent; {$ENDREGION} strict protected /// <summary> /// Clean up any resources being used. /// </summary> procedure Dispose(Disposing: Boolean); override; private { Private Declarations } public constructor Create; end; [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))] implementation {$AUTOBOX ON} {$REGION 'Windows Form Designer generated code'} /// <summary> /// Required method for Designer support -- do not modify /// the contents of this method with the code editor. /// </summary> procedure TWinForm.InitializeComponent; begin Self.DataGrid1 := System.Windows.Forms.DataGrid.Create; (System.ComponentModel.ISupportInitialize(Self.DataGrid1)).BeginInit; Self.SuspendLayout; // // DataGrid1 // Self.DataGrid1.DataMember := ''; Self.DataGrid1.HeaderForeColor := System.Drawing.SystemColors.ControlText; Self.DataGrid1.Location := System.Drawing.Point.Create(8, 16); Self.DataGrid1.Name := 'DataGrid1'; Self.DataGrid1.Size := System.Drawing.Size.Create(280, 240); Self.DataGrid1.TabIndex := 0; // // TWinForm // Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13); Self.ClientSize := System.Drawing.Size.Create(292, 266); Self.Controls.Add(Self.DataGrid1); Self.Name := 'TWinForm'; Self.Text := 'WinForm'; (System.ComponentModel.ISupportInitialize(Self.DataGrid1)).EndInit; Self.ResumeLayout(False); end; {$ENDREGION} procedure TWinForm.Dispose(Disposing: Boolean); begin if Disposing then begin if Components <> nil then Components.Dispose(); end; inherited Dispose(Disposing); end; constructor TWinForm.Create; begin inherited Create; // // Required for Windows Form Designer support // InitializeComponent; // // TODO: Add any constructor code after InitializeComponent call // end; end. ======================= unit DataSetU; interface Uses System.Data, Borland.Data.Provider; Type TMiBD = Record MiDataSet : DataSet; MiAdaptador : BdpDataAdapter; MiConexion : BdpConnection; MiComando : BdpCommand; End; Var MiBD : TMiBD; implementation Begin With MiBD Do Begin MiDataSet := DataSet.Create ( 'MiBD'); MiConexion := BdpConnection.Create; MiConexion.ConnectionOptions := 'transaction isolation' + '=ReadCommitted'; MiConexion.ConnectionString := 'database=Ecodomes;asse' + 'mbly=Borland.Data.Oracle, Version=2.0.0.0, Culture=neutral, PublicKeyToke' + 'n=91d62ebb5b0d1b1b;vendorclient=oci.dll;provider=Oracle;username=system;p' + 'assword=cz4lg3'; MiComando := Borland.Data.Provider.BdpCommand.Create; MiComando.CommandOptions := nil; MiComando.CommandText := 'select * from usuarios'; MiComando.CommandType := System.Data.CommandType.Text; MiComando.Connection := MiConexion; MiComando.ParameterCount := (SmallInt(0)); MiComando.SchemaName := nil; MiComando.Transaction := nil; MiCOmando.UpdatedRowSource := System.Data.UpdateRowSource.None; MiAdaptador := BDPDataAdapter.Create; MiAdaptador.DataSet := MiDataSet; MiAdaptador.SelectCommand := MiComando; MiAdaptador.SelectCommand.CommandText := 'select * from usuarios'; MiAdaptador.Fill(MiDataSet); MiAdaptador.Active := True; End; end. |
|
#2
|
|||
|
|||
|
Buenas, al fin he conseguido realizar lo que quería, que es utilizar el componente dataset de la barra de componentes de delphi pero haciendo que este sea público, es decir, que pueda acceder desde otra unidad. La solución ha sido bastante sencilla.
unit UNIDAD1; =========== Type MyDS = Class(DataSet) Public Constructor Create; Overload; End; Constructor MyDS.Create; Begin Self.Create('MyDs'); End; unit WinFormU; =========== type TWinForm = class(System.Windows.Forms.Form) strict private DataSet1: DataSetU.MyDS; //DataSet1 es el componente utilizado desde la barra de componentes de delphi. End; procedure TWinForm.InitializeComponent; begin Self.DataSet1 := Unidad1.MyDS.Create; End; |
|
#3
|
|||
|
|||
|
unit WinForm;
{En esta unidad insertamos los componentes BdpConnection1 y BdpAdapter1 de la plaeta de componentes y el DataSet lo creamos manualmente a través de una variable.} interface uses System.Drawing, System.Collections, System.ComponentModel, System.Windows.Forms, System.Data, System.Data.Common, Borland.Data.Provider, System.Globalization; type TWinForm = class(System.Windows.Forms.Form) {$REGION 'Designer Managed Code'} strict private /// <summary> /// Required designer variable. /// </summary> Components: System.ComponentModel.Container; BdpConnection1: Borland.Data.Provider.BdpConnection; bdpSelectCommand1: Borland.Data.Provider.BdpCommand; bdpInsertCommand1: Borland.Data.Provider.BdpCommand; bdpUpdateCommand1: Borland.Data.Provider.BdpCommand; bdpDeleteCommand1: Borland.Data.Provider.BdpCommand; BdpDataAdapter1: Borland.Data.Provider.BdpDataAdapter; Button1: System.Windows.Forms.Button; /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> procedure InitializeComponent; procedure Button1_Click(sender: System.Object; e: System.EventArgs); {$ENDREGION} strict protected /// <summary> /// Clean up any resources being used. /// </summary> procedure Dispose(Disposing: Boolean); override; private { Private Declarations } public constructor Create; end; [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))] Var DatasetPublico : System.Data.DataSet; implementation uses WinForm1; {El datasource del datagrid1 = al dataset creado en la unidad anterior. Este formulario saldrá al presionar al boton1 creado en el formulario anterior.} {$AUTOBOX ON} {$REGION 'Windows Form Designer generated code'} /// <summary> /// Required method for Designer support -- do not modify /// the contents of this method with the code editor. /// </summary> procedure TWinForm.InitializeComponent; begin DataSetPublico := System.Data.DataSet.Create; Self.BdpConnection1 := Borland.Data.Provider.BdpConnection.Create; Self.bdpSelectCommand1 := Borland.Data.Provider.BdpCommand.Create; Self.bdpInsertCommand1 := Borland.Data.Provider.BdpCommand.Create; Self.bdpUpdateCommand1 := Borland.Data.Provider.BdpCommand.Create; Self.bdpDeleteCommand1 := Borland.Data.Provider.BdpCommand.Create; Self.BdpDataAdapter1 := Borland.Data.Provider.BdpDataAdapter.Create; Self.Button1 := System.Windows.Forms.Button.Create; (System.ComponentModel.ISupportInitialize(Self.BdpDataAdapter1)).BeginInit; Self.SuspendLayout; // // BdpConnection1 // Self.BdpConnection1.ConnectionOptions := 'transaction isolation=ReadCommit' + 'ted'; Self.BdpConnection1.ConnectionString := 'assembly=Borland.Data.Oracle, Ver' + 'sion=2.0.0.0, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b;vendorclie' + 'nt=oci.dll;database=Ecodomes;provider=Oracle;username=system;password=cz4' + 'lg3'; // // bdpSelectCommand1 // Self.bdpSelectCommand1.CommandOptions := nil; Self.bdpSelectCommand1.CommandText := 'select * from usuarios'; Self.bdpSelectCommand1.CommandType := System.Data.CommandType.Text; Self.bdpSelectCommand1.Connection := Self.BdpConnection1; Self.bdpSelectCommand1.ParameterCount := (SmallInt(0)); Self.bdpSelectCommand1.SchemaName := nil; Self.bdpSelectCommand1.Transaction := nil; Self.bdpSelectCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None; // // bdpInsertCommand1 // Self.bdpInsertCommand1.CommandOptions := nil; Self.bdpInsertCommand1.CommandText := nil; Self.bdpInsertCommand1.CommandType := System.Data.CommandType.Text; Self.bdpInsertCommand1.Connection := nil; Self.bdpInsertCommand1.ParameterCount := (SmallInt(0)); Self.bdpInsertCommand1.SchemaName := nil; Self.bdpInsertCommand1.Transaction := nil; Self.bdpInsertCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None; // // bdpUpdateCommand1 // Self.bdpUpdateCommand1.CommandOptions := nil; Self.bdpUpdateCommand1.CommandText := nil; Self.bdpUpdateCommand1.CommandType := System.Data.CommandType.Text; Self.bdpUpdateCommand1.Connection := nil; Self.bdpUpdateCommand1.ParameterCount := (SmallInt(0)); Self.bdpUpdateCommand1.SchemaName := nil; Self.bdpUpdateCommand1.Transaction := nil; Self.bdpUpdateCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None; // // bdpDeleteCommand1 // Self.bdpDeleteCommand1.CommandOptions := nil; Self.bdpDeleteCommand1.CommandText := nil; Self.bdpDeleteCommand1.CommandType := System.Data.CommandType.Text; Self.bdpDeleteCommand1.Connection := nil; Self.bdpDeleteCommand1.ParameterCount := (SmallInt(0)); Self.bdpDeleteCommand1.SchemaName := nil; Self.bdpDeleteCommand1.Transaction := nil; Self.bdpDeleteCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None; // // BdpDataAdapter1 // Self.BdpDataAdapter1.DataSet := DataSetPublico; Self.BdpDataAdapter1.Active := True; Self.BdpDataAdapter1.DataTable := nil; Self.BdpDataAdapter1.DeleteCommand := Self.bdpDeleteCommand1; Self.BdpDataAdapter1.InsertCommand := Self.bdpInsertCommand1; Self.BdpDataAdapter1.SelectCommand := Self.bdpSelectCommand1; Self.BdpDataAdapter1.StartRecord := 0; Self.BdpDataAdapter1.UpdateCommand := Self.bdpUpdateCommand1; // // Button1 // Self.Button1.Location := System.Drawing.Point.Create(80, 104); Self.Button1.Name := 'Button1'; Self.Button1.TabIndex := 0; Self.Button1.Text := 'Button1'; Include(Self.Button1.Click, Self.Button1_Click); // // TWinForm // Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13); Self.ClientSize := System.Drawing.Size.Create(292, 266); Self.Controls.Add(Self.Button1); Self.Name := 'TWinForm'; Self.Text := 'WinForm'; (System.ComponentModel.ISupportInitialize(Self.BdpDataAdapter1)).EndInit; Self.ResumeLayout(False); end; {$ENDREGION} procedure TWinForm.Dispose(Disposing: Boolean); begin if Disposing then begin if Components <> nil then Components.Dispose(); end; inherited Dispose(Disposing); end; constructor TWinForm.Create; begin inherited Create; // // Required for Windows Form Designer support // InitializeComponent; // // TODO: Add any constructor code after InitializeComponent call // end; procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs); begin TWinform1.Create.Show; end; end. unit WinForm1; interface uses System.Drawing, System.Collections, System.ComponentModel, System.Windows.Forms, System.Data; type TWinForm1 = class(System.Windows.Forms.Form) {$REGION 'Designer Managed Code'} strict private /// <summary> /// Required designer variable. /// </summary> Components: System.ComponentModel.Container; DataGrid1: System.Windows.Forms.DataGrid; /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> procedure InitializeComponent; procedure TWinForm1_Load(sender: System.Object; e: System.EventArgs); {$ENDREGION} strict protected /// <summary> /// Clean up any resources being used. /// </summary> procedure Dispose(Disposing: Boolean); override; private { Private Declarations } public constructor Create; end; [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm1))] implementation uses WinForm; {$AUTOBOX ON} {$REGION 'Windows Form Designer generated code'} /// <summary> /// Required method for Designer support -- do not modify /// the contents of this method with the code editor. /// </summary> procedure TWinForm1.InitializeComponent; begin Self.DataGrid1 := System.Windows.Forms.DataGrid.Create; (System.ComponentModel.ISupportInitialize(Self.DataGrid1)).BeginInit; Self.SuspendLayout; // // DataGrid1 // Self.DataGrid1.DataMember := ''; Self.DataGrid1.HeaderForeColor := System.Drawing.SystemColors.ControlText; Self.DataGrid1.Location := System.Drawing.Point.Create(16, 16); Self.DataGrid1.Name := 'DataGrid1'; Self.DataGrid1.Size := System.Drawing.Size.Create(256, 232); Self.DataGrid1.TabIndex := 0; // // TWinForm1 // Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13); Self.ClientSize := System.Drawing.Size.Create(292, 266); Self.Controls.Add(Self.DataGrid1); Self.Name := 'TWinForm1'; Self.Text := 'WinForm1'; Include(Self.Load, Self.TWinForm1_Load); (System.ComponentModel.ISupportInitialize(Self.DataGrid1)).EndInit; Self.ResumeLayout(False); end; {$ENDREGION} procedure TWinForm1.Dispose(Disposing: Boolean); begin if Disposing then begin if Components <> nil then Components.Dispose(); end; inherited Dispose(Disposing); end; constructor TWinForm1.Create; begin inherited Create; // // Required for Windows Form Designer support // InitializeComponent; // // TODO: Add any constructor code after InitializeComponent call // end; procedure TWinForm1.TWinForm1_Load(sender: System.Object; e: System.EventArgs); begin DataGrid1.DataSource := DataSetPublico; end; end. |
|
#4
|
||||
|
||||
|
Por favor, en lo adelante, intenta de copiar el codigo delphi dentro de etiquetas de formateo de codigo, tales como [ CODE ] [ / CODE ] y/o [ delphi ] [ /delphi ] (omitiendo los espacios entre los corchetes y la palabra)
Eso hara mas legible el codigo que muestras.
__________________
Héctor Geraldino Software Engineer |
|
#5
|
|||
|
|||
|
Ok
Ok, así lo haré. Desconocía esa utilidad.
Saludos. |
![]() |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
|