Ver Mensaje Individual
  #6  
Antiguo 13-07-2007
Arturo_ Arturo_ is offline
Miembro
 
Registrado: jul 2007
Posts: 48
Reputación: 0
Arturo_ Va por buen camino
Arturo_ te: ayuda con tabla en delphi

En la segunda table para guardar mas productos lo que tienes que hacer es sensillo: Antes de ingresar un nuevo producto debes dar un Table2.Append para que el sistema le asigne una nueva posición de registro a tu prodcuto.
Ejemplo:

// Aqui se inserta un nuevo registro para un nuevo producto
// Si la tabla esta vacia toma el primer registro por defecto
// Si no esta vacia inserta un nuevo registro

if (Table2.RecordCount <> 0) then
Table2.Append

Table2.Edit
Table2.FieldByName('Productp').AsString := 'xxxxx';
Table2.Post

Claro esta que tienes que tener bien enlazadas las tablas:
Tabla1 y
Tabl22

Cuando ingreses un nuevo registro usa el evento BeforPost en el cual tienes que extraer el ultimo el valor del ultimo registro y sumarle 1 para el nuevo registro.

He publicado una rutina en Tables Planas 'Maximo Valor para un Nuevo Registro', esto te servira si lo usas de la manera correcta.

Ejemplo: Evento -> BeforePost

procedure TForm_BeEMPPRJ.Table2BeforePost(DataSet: TDataSet);
begin
if (Table2.State = dsInsert) then
begin
Table2.Value := Table1.FieldByName('LINK_0001').AsFloat;
ASSEMBLY_RECORD_MaxKey(Table2, 'LINK_0002');

// Init_VALUES_TABLE
Table2Edit;
if (Table2Producto.IsNULL) then
Table2Producto.Value := '';
end;
end;

// Versión: 10.0000 - © 1980, 2006 For Tables DELPHI SERVER .DB
// Ejecutar en: El Evento <Table.BeforePos> ****
// Función que Extrae el Valor Maximo para un Nuevo Registro Key
// Con este Procedimiento ya no se Necesita Utilizar las Tablas: // Ejemplos:
// Form_DDBTLM.ASSEMBLY_RECORD_MaxKey(Table_NN, 'LINK_0001');
// Form_DDBTLM.ASSEMBLY_RECORD_MaxKey(Table_NN, 'LINK_0002');
// Form_DDBTLM.ASSEMBLY_RECORD_MaxKey(Table_NN, 'LINK_0003');

procedure TForm_BeEMPPRJ.ASSEMBLY_RECORD_MaxKey(var pmt_TABLE: TTable; pmt_FIELD: string);
begin
// Init_PROPERTIES
if (Table_ARMK.Active) then Table_ARMK.Close;
Table_ARMK.Filter := '';
Table_ARMK.Filtered := False;
Table_ARMK.IndexFieldNames := '';
Table_ARMK.MasterFields := '';
Table_ARMK.MasterSource := nil;
// Assign_PROPERTIES
Table_ARMK.DatabaseName := pmt_TABLE.DatabaseName;
Table_ARMK.SessionName := pmt_TABLE.SessionName;
Table_ARMK.TableName := pmt_TABLE.TableName;
Table_ARMK.MasterSource := pmt_TABLE.MasterSource;
Table_ARMK.MasterFields := pmt_TABLE.MasterFields;
if (Table_ARMK.MasterFields = '') then
Table_ARMK.IndexFieldNames := pmt_FIELD
else
Table_ARMK.IndexFieldNames := Table_ARMK.MasterFields + ';' + pmt_FIELD;
// Open_TABLE
Table_ARMK.Open;
Table_ARMK.Last;
// Load_RECORD_KEY
if (Table_ARMK.RecordCount = 0) then
pmt_TABLE.FieldByName(pmt_FIELD).AsFloat := 1
else
pmt_TABLE.FieldByName(pmt_FIELD).AsFloat := Table_ARMK.FieldByName(pmt_FIELD).AsFloat + 1;
// Close_TABLE
Table_ARMK.Close;
end;

Claro esta que los enlaces LINK_0001 LINK_0002, LINK_0003 los uso de una forma dinamica para enlazar tablas paradox:

Por ejemplo en tus dos tablas Tabla1 el Primary Key seria LINK_0001
Y en tu Table2 el Primary Key seria LINK_0002, claro esta que en la tabla2 el indice LINK_0001 seria el enlace con el indice LINK_0001 de la Tabla1.

Espero que te sirva...

Última edición por Arturo_ fecha: 13-07-2007 a las 23:05:45.
Responder Con Cita