Delphi - Ayuda con Runtime Delphi

 
Vista:
sin imagen de perfil

Ayuda con Runtime Delphi

Publicado por Ema (5 intervenciones) el 22/02/2014 18:09:05
Hola, tengo un problema que me lleva loco ya hace rato.
Estoy trabajando en un soft que registra un despacho, y resulta que trabajo con pagecontrol y sus tabsheets dinamicos, funciona asi: se recibe un llamado y cuando se registra un incidente (en el evento on click) se genera una nueva hoja dinamica, que ya esta establecida.. (hasta ahi todo bien) hay un boton que sirve para modificar los datos que ingrese al principio y crea un form tambien dinamico que contiene los dbedits de c/u de los campos de la tabla a modificar.
Cuando yo creo varios incidentes es donde se produce el problema, por que me toma el ultimo registro que cargue al principio, y no los anteriores correspondientes, y el form se crea de forma unica para todos los tabsheets, es ahi donde tengo el problema, he probado hacer los tabsheets en array... etc.. pero no resulta aca le pongo una parte del codigo..
//ESTE ME CREA EL TABSHEET EN TIEMPO DE EJECUCION---
tabtmp:= Ttabsheet.Create(paginarecibo);
tabtmp.PageControl := paginarecibo;
tabtmp.Name:= 'tabSheet' + inttostr(paginarecibo.PageCount);
tabTmp.Caption := 'INCIDENTE Nº' + codegcia1.Text;
paginarecibo.ActivePage:=tabtmp;
with tabtmp do
begin
listapersonal:= Tdblookuplistbox.Create(self);
listapersonal.SetBounds(182, 56, 179, 212);
listapersonal.Parent:= tabtmp;
listapersonal.ListSource:= datapers;
listapersonal.ListField:= 'nom_p';
listapersonal.KeyField:='id_p';
listapersonal2:=Tlistbox.Create(self);
listapersonal2.SetBounds(384,88,179,180);
listapersonal2.Parent:= tabtmp;
jefdot:= Tcombobox.Create(self);
jefdot.SetBounds(384,56,179,21);
jefdot.Parent:= tabtmp;
labelid:= Tlabel.Create(self);
labelid.Caption:= inttostr(idinci);
labelid.SetBounds(584,13,31,13);
labelid.Parent:= tabtmp;
with save do
begin
save:= tbitbtn.Create(self);
save.SetBounds(182,274,179,25);
save.Parent:= tabtmp;
save.Caption:='AGREGAR A DOTACION';
save.OnClick:= proc1;
end;
with quit do
begin
quit:=Tbitbtn.Create(self);
quit.SetBounds(384,274,179,25);
quit.Parent:= tabtmp;
quit.Caption:='BAJAR DE DOTACION';
quit.OnClick:=proc2;
end;
with modin do
begin
modin:= Tbitbtn.Create(self);
modin.SetBounds(704,296,105,25);
modin.Parent:= tabtmp;
modin.Caption:='MODIFICAR DATOS INCIDENTE';
modin.OnClick:=modindatos;
end;
with labels do
begin
labels:= tlabel.Create(self);
labels.SetBounds(208,13,121,28);
labels.Caption:='DOTACION';
labels.Font.Name:= 'Arial Black' ;
labels.Font.Size:= 15;
labels.Parent:= tabtmp;
end;
with labels1 do
begin
labels1:= tlabel.Create(self);
labels1.SetBounds(381,13,121,28);
labels1.Caption:='JEFE DOTACION';
labels1.Font.Name:= 'Arial Black' ;
labels1.Font.Size:= 15;
labels1.Parent:= tabtmp;
end;
with finemer do
begin
finemer:=tbitbtn.Create(self);
finemer.SetBounds(507,387,75,25);
finemer.Parent:=tabtmp;
finemer.Caption:='FIN';
finemer.OnClick:= fin;
end;
o:= 30;
with desp_1 do
begin
sql.Clear;
sql.Text:= 'select * from m_t order by m_n asc ';
open;
end;
SetLength(botones, datadesp1.DataSet.RecordCount);
for i:= low(botones) to high(botones) do
begin
num:=datadesp1.DataSet.FieldValues['m_n'];
botones[i]:= tbutton.Create(tabtmp);
botones[i].SetBounds(9,i*30,136,25);
botones[i].parent:= tabtmp;
botones[i].caption:= (datadesp1.dataset.FieldByName('m_n').AsString);
datadesp1.DataSet.Next;
end;
end;

//ESTE ME CREA EL FORM A DONDE SE CREAN TAMBIEN LOS DBEDITS PARA MODIFICAR//
procedure Tdespacho.modindatos;
var
cap1,cap2,cap3,cap4,cap5,cap6: Tlabel;
botmod: Tbitbtn;
begin
formmodifin := TForm.Create(tabtmp);
Formmodifin.SetBounds(201,90,497,257);
Formmodifin.Parent:= self;
Formmodifin.Caption:='MODIFICAR DATOS INCIDENTE Nº'+ inttostr(idinci);
formmodifin.Enabled:=true;
Formmodifin.FormStyle:= fsStayOnTop;
formmodifin.BorderStyle:=Bsdialog;
formmodifin.Show;
botmod:= Tbitbtn.Create(tabtmp);
botmod.SetBounds(120,168,130,25);
botmod.Caption:='MODIFICAR INCIDENTE';
botmod.Parent:= formmodifin;
botmod.OnClick:=modif;
botcancelmod:=Tbitbtn.Create(tabtmp);
botcancelmod.SetBounds(256,168,130,25);
botcancelmod.Parent:=formmodifin;
botcancelmod.Caption:='CANCELAR';
botcancelmod.OnClick:=cancelador;
idinci:= strtoint(labelid.Caption);
with queriinci do
begin
sql.Clear;
sql.Text:='select * from salida_emer where id_inci=:idinci';
parameters[0].Value:=idinci;
open;
end;
datainci.DataSet.FieldValues['dir_emer1'];
cedit1:=Tdbedit.Create(tabtmp);
cedit1.SetBounds(120,8,327,21);
cedit1.Parent:= formmodifin;
cedit1.DataSource:=datainci;
cedit1.DataField:='dir_emer1';
cedit2:=Tdbedit.Create(tabtmp);
cedit2.SetBounds(120,38,327,21);
cedit2.Parent:= formmodifin;
cedit2.DataSource:=datainci;
cedit2.DataField:='dir_emer2';
cedit3:=Tdbedit.Create(tabtmp);
cedit3.SetBounds(120,68,327,21);
cedit3.Parent:= formmodifin;
cedit3.DataSource:=datainci;
cedit3.DataField:='dir_emer3';
cedit4:=Tdbedit.Create(tabtmp);
cedit4.SetBounds(120,98,327,21);
cedit4.Parent:= formmodifin;
cedit4.DataSource:=datainci;
cedit4.DataField:='nom_emer';
cedit5:=Tdbedit.Create(tabtmp);
cedit5.SetBounds(120,128,327,21);
cedit5.Parent:= formmodifin;
cedit5.DataSource:=datainci;
cedit5.DataField:='tel';
end;


// El problema como comente se da que cuando hay multiples tabsheets creados dinamicamente, me toma el ultimo registro en el form, y no los que corresponden a cada uno.
Gracias por la ayuda de antemano!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 65
Oro
Ha mantenido su posición en Delphi (en relación al último mes)
Gráfica de Delphi

Ayuda con Runtime Delphi

Publicado por E.T. (1244 intervenciones) el 22/02/2014 19:21:56
El problema está, y esto lo estoy suponiendo, en tu variable "idinci", que haces con ella, cada vez que agregas un incidente? la incrementas?
Tambien veo que en el procedimeinto de modificar, tomas el valor que tiene la varibale labelid y la asignas a idinci, aqui está el problema, pues la variable labelid tiene como valor el ultimo label creado, no el del tab seleccionado, la solucion que yo te propongo es la siguiente:
Suponiendo que idinci siempre es un numero

1
2
3
4
5
6
//Al crear tu tabSheet, usa su propiedad "Tag": asi
tabtmp:= Ttabsheet.Create(paginarecibo);
tabtmp.PageControl := paginarecibo;
tabtmp.Name:= 'tabSheet' + inttostr(paginarecibo.PageCount);
tabTmp.Caption := 'INCIDENTE Nº' + codegcia1.Text;
tabTmp.Tag := idinci;

y cuando quieres modificar alguna, sería lo siguiente:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//ESTE ME CREA EL FORM A DONDE SE CREAN TAMBIEN LOS DBEDITS PARA MODIFICAR//
procedure Tdespacho.modindatos;
var
cap1,cap2,cap3,cap4,cap5,cap6: Tlabel;
botmod: Tbitbtn;
begin
formmodifin := TForm.Create(tabtmp);
Formmodifin.SetBounds(201,90,497,257);
Formmodifin.Parent:= self;
idinci := paginarecibo.Pages[paginarecibo.TabIndex].Tag; //Esta linea es la clave<--------------------------------
//YA no modifiques la variable a partir de aqui
Formmodifin.Caption:='MODIFICAR DATOS INCIDENTE Nº'+ inttostr(idinci);
//Continua la ejecucion normal, sin modificar  idinci 
// la siguiente linea la quitas o la comentas
//idinci:= strtoint(labelid.Caption);

Prueba y me dices si te funciona
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Ayuda con Runtime Delphi

Publicado por Ema (5 intervenciones) el 22/02/2014 19:59:45
Ahi funciono con tu arreglo, eso era lo que necesitaba, nunca se me habría ocurido usar el tag. Muchisimas Gracias, en serio me salvaste las papas! Gracias un abrazo!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Ayuda con Runtime Delphi

Publicado por ema (5 intervenciones) el 01/03/2014 17:08:29
Hola yo nuevamente, tengo el mismo problema que antes, pero esta vez es con el mismo tabsheet! resulta que puse Dbtexts, que leen los datos del incidente y los muestra mientras esta abierto ese tabsheet. El problema surge cuando creo mas de 1 incidente y me muestra los datos del ultimo incidente registrado y no el que corresponde a cada tabsheet! ya probe setearlo con los tags, pero igualmente sigo con el mismo problema, incluso cree un array de tabsheet y le di un INC[contador] a c/u pero igual... Me podrias ayudar nuevamente? Que pena con usted! pero me esta superando nuevamente... gracias y disculpe la molestia!
Aca va nuevamente el codigo:

//CREADOR DINAMICO DE TODA LA HOJA//
Inc(contador);
tabtmp[contador]:= Ttabsheet.Create(paginarecibo);
with tabtmp[contador] do
tabtmp[contador].PageControl := paginarecibo;
tabtmp[contador].Name:= 'tabSheet' + inttostr(paginarecibo.PageCount);
tabtmp[contador].Caption := 'INCIDENTE Nº' + inttostr(idinci);
tabtmp[contador].Tag := idinci;
paginarecibo.ActivePage:=tabtmp[contador];
with tabtmp[contador] do
begin
listapersonal:= Tdblookuplistbox.Create(self);
listapersonal.SetBounds(182, 56, 179, 212);
listapersonal.Parent:= tabtmp[contador];
listapersonal.ListSource:= datapers;
listapersonal.ListField:= 'nom_p';
listapersonal.KeyField:='id_p';
listapersonal2:=Tlistbox.Create(self);
listapersonal2.SetBounds(384,88,179,180);
listapersonal2.Parent:= tabtmp[contador];
jefdot:= Tcombobox.Create(self);
jefdot.SetBounds(384,56,179,21);
jefdot.Parent:= tabtmp[contador];
labelid:= Tlabel.Create(self);
labelid.Caption:= inttostr(idinci);
labelid.SetBounds(584,13,31,13);
labelid.Parent:= tabtmp[contador];
with save do
begin
save:= tbitbtn.Create(self);
save.SetBounds(182,274,179,25);
save.Parent:= tabtmp[contador];
save.Caption:='AGREGAR A DOTACION';
save.OnClick:= proc1;
end;
with quit do
begin
quit:=Tbitbtn.Create(self);
quit.SetBounds(384,274,179,25);
quit.Parent:= tabtmp[contador];
quit.Caption:='BAJAR DE DOTACION';
quit.OnClick:=proc2;
end;
with modin do
begin
modin:= Tbitbtn.Create(self);
modin.SetBounds(704,296,105,25);
modin.Parent:= tabtmp[contador];
modin.Caption:='MODIFICAR DATOS INCIDENTE';
modin.OnClick:=modindatos;
end;
with labels do
begin
labels:= tlabel.Create(self);
labels.SetBounds(208,13,121,28);
labels.Caption:='DOTACION';
labels.Font.Name:= 'Arial Black' ;
labels.Font.Size:= 15;
labels.Parent:= tabtmp[contador];
end;
with labels1 do
begin
labels1:= tlabel.Create(self);
labels1.SetBounds(381,13,121,28);
labels1.Caption:='JEFE DOTACION';
labels1.Font.Name:= 'Arial Black' ;
labels1.Font.Size:= 15;
labels1.Parent:= tabtmp[contador];
end;
with l1 do
begin
l1:= tlabel.Create(self);
l1.SetBounds(624,53,41,13);
l1.Caption:='REGISTRO INCIDENTE Nº:';
L1.Font.Size:= 10;
l1.Parent:= tabtmp[contador];
end;
with l2 do
begin
l2:= tlabel.Create(self);
l2.SetBounds(624,73,41,13);
l2.Caption:='DIRECCION:';
L2.Font.Size:= 10;
l2.Parent:= tabtmp[contador];
end;
with l3 do
begin
l3:= tlabel.Create(self);
l3.SetBounds(624,93,41,13);
l3.Caption:='ENTRE CALLE 1:';
L3.Font.Size:= 10;
l3.Parent:= tabtmp[contador];
end;
with l4 do
begin
l4:= tlabel.Create(self);
l4.SetBounds(624,113,41,13);
l4.Caption:='ENTRE CALLE 2:';
L4.Font.Size:= 10;
l4.Parent:= tabtmp[contador];
end;
with L5 do
begin
l5:= tlabel.Create(self);
l5.SetBounds(624,133,41,13);
l5.Caption:='NOMBRE LLAMANTE:';
L5.Font.Size:= 10;
l5.Parent:= tabtmp[contador];
end;
with l6 do
begin
l6:= tlabel.Create(self);
l6.SetBounds(624,153,41,13);
l6.Caption:='TELEFONO:';
L6.Font.Size:= 10;
l6.Parent:= tabtmp[contador];
end;
with l7 do
begin
l7:= tlabel.Create(self);
l7.SetBounds(624,173,41,13);
l7.Caption:='TIPO INCIDENTE:';
L7.Font.Size:= 10;
l7.Parent:= tabtmp[contador];
end;
with l8 do
begin
l8:= tlabel.Create(self);
l8.SetBounds(624,192,41,13);
l8.Caption:='CODIGO:';
L8.Font.Size:= 10;
l8.Parent:= tabtmp[contador];
end;
// A PARTIR DE ACA ME EMPIEZA A CREAR LOS TDBTEXT DINAMICOS--> LOS QUE MUESTRAN EL MISMO CONTENIDO EN CADA UNA DE LAS TABSHEETS, CUANDO DEBERIA MOSTRAR EL PROPIO A CADA TABSHEET//
idinci := paginarecibo.Pages[paginarecibo.TabIndex].Tag;
with inci1 do
begin
sql.Clear;
sql.Text:='Select * from salida_emer where id_inci=:idinci ';
parameters[0].Value:=idinci;
open;
end;
with lt1 do
begin
lt1:=tdbtext.Create(self);
lt1.SetBounds(768,59,225,17);
lt1.Parent:= tabtmp[contador];
lt1.DataSource:= dinc;
lt1.DataField:='id_inci';
end;
with lt2 do
begin
LT2:=tdbtext.Create(self);
LT2.SetBounds(768,78,250,17);
LT2.Parent:= tabtmp[contador];
LT2.DataSource:= dinc;
LT2.DataField:='dir_emer1';
end;
with lt3 do
begin
LT3:=tdbtext.Create(self);
LT3.SetBounds(768,97,250,17);
LT3.Parent:= tabtmp[contador];
LT3.DataSource:= dinc;
LT3.DataField:='dir_emer2';
end;
with lt4 do
begin
LT4:=tdbtext.Create(self);
LT4.SetBounds(768,116,250,17);
LT4.Parent:= tabtmp[contador];
LT4.DataSource:= dinc;
LT4.DataField:='dir_emer3';
end;
with lt5 do
begin
LT5:=tdbtext.Create(self);
LT5.SetBounds(768,135,250,17);
LT5.Parent:= tabtmp[contador];
LT5.DataSource:= dinc;
LT5.DataField:='nom_emer';
end;
with lt6 do
begin
LT6:=tdbtext.Create(self);
LT6.SetBounds(768,154,250,17);
LT6.Parent:= tabtmp[contador];
LT6.DataSource:= dinc;
LT6.DataField:='tel';
end;
with lt7 do
begin
LT7:=tdbtext.Create(self);
LT7.SetBounds(768,173,250,17);
LT7.Parent:= tabtmp[contador];
LT7.DataSource:= dinc;
LT7.DataField:='cod_emer';
end;
with lt8 do
begin
LT8:=tdbtext.Create(self);
LT8.SetBounds(768,192,250,17);
LT8.Parent:= tabtmp[contador];
LT8.DataSource:= dinc;
LT8.DataField:='clave_emer';
end;
end;
with finemer do
begin
finemer:=tbitbtn.Create(self);
finemer.SetBounds(507,387,75,25);
finemer.Parent:=tabtmp[contador];
finemer.Caption:='FIN';
finemer.OnClick:= fin;
end;
o:= 30;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar