Ir al contenido


Foto

programa tipo agenda


  • Por favor identifícate para responder
3 respuestas en este tema

#1 Alicia m

Alicia m

    Newbie

  • Miembros
  • Pip
  • 1 mensajes

Escrito 29 junio 2016 - 06:40

hola....

 

solo deseo que me den una idea.

Recién estoy aprendiendo hacer aplicaciones en Delphi, se lo mínimo... 

 

Deseo hacer una aplicación, similar a una agenda, que me permita almacenar datos de personas, en columnas (que me muestre en columnas)...

 

////   apellido  // apellido   ////    estado civil     ////  Horas Trabajadas  ////   profesión/trabajo     ////     campoA     ////     CampoB     ////  

 

//// Arias //// josee              ////       soltero         ////           20                ////       cocinero               ////       azul 1    ////       beta            ////       

//// Arias  //// luisa               ////       soltero         ////           230              ////       zapatero               ////       azul2    ////       beta            ////     

//// Villega ////s leon             ////       viudo          ////           110                ////       cocinero               ////       azul 1    ////      alfaa            ////  

////  Millan //// Matia              ////       casado      ////           201                ////       abogado               ////       rojo 1    ////       omega        ////  

//// Gollk  //// josee              ////       viudo         ////            120                ////       maestro                ////     negro 1    ////       beta            ////         

 

 .........

 

 

Quiero hacer la aplicación bien sencilla...

 

Lo único que ara es:

********** ingresar los datos,

********** almacenarlos,

********** modificaros si es necesario,

********** poder ordenarlos según la columna,( nombre, apellido, Horas trabajadas,  campoA, CampoB)

 

No pido que me hagan el programa, solo que me den una idea......

.... pero también se aceptan ejemplos si lo tienen.. gracias 

 

 

Tengo delphi 5 para trabajar.

 


  • 0

#2 BDWONG

BDWONG

    Member

  • Miembros
  • PipPip
  • 28 mensajes

Escrito 29 junio 2016 - 10:00

Hola te puedo dar una idea y es el crear un objeto de tipo TPersona con todos los atributos ejemplo nombre,apellido,profesion etc. Tambien utilizar TObjectList para almacenar a todas las personas  y manejarlas de manera mas comoda que usando arreglos te dejo un simple ejemplo

 

Unit TPersona


delphi
  1. type
  2. TEstadoCivil=(casado,soltero);
  3.  
  4. { TTrabajador }
  5.  
  6. TPersona=class(TObject)
  7. private
  8. fnombre:String;
  9. fapellido:String;
  10. festadoCivil:TEstadoCivil;
  11. fprofesion:String;
  12. fcampoA:String;
  13. fcampoB:String;
  14. public
  15. constructor create(nombre:string; pellido:String; estadoCivil:TEstadoCivil; profesion:String; campoA:String; campoB:String);
  16. property nombre:String read fnombre write fnombre;
  17. property apellido:string read fapellido write fapellido;
  18. property estadoCivil: TEstadoCivil read festadoCivil write festadoCivil;
  19. end;
  20.  
  21. implementation
  22.  
  23. { TTrabajador }
  24.  
  25.  
  26. constructor TPersona.create(nombre: string; pellido: String;
  27. estadoCivil: TEstadoCivil; profesion: String; campoA: String; campoB: String);
  28. begin
  29. inherited create;
  30. self.fnombre:=nombre;
  31. self.fapellido:=apellido;
  32. self.festadoCivil:=estadoCivil;
  33. self.fprofesion:=profesion;
  34. self.fcampoA:=campoA;
  35. self.fcampoB:=campoB;
  36. end;
  37.  
  38.  
  39. end.

Uso de la unit


delphi
  1. var
  2. listaPersona:TObjectList;
  3. t1,t2:TPersona;
  4. i:Integer;
  5. begin
  6. t1:=TPersona.create('jose','garcia',casado,'policia','azul 1','beta');
  7. t2:=TPersona.create('luis','villega',soltero,'cocinero','azul 1','alfa');
  8.  
  9. listaPersona:=TObjectList.Create(True);
  10. listaPersona.Add(t1);
  11. listaPersona.Add(t2);
  12.  
  13. for i:=0 to listaPersona.Count-1 do
  14. WriteLn(TPersona(listaPersona[i]).nombre);
  15.  
  16. listaPersona.Free;
  17. ReadLn;
  18. end.

Si tienes dudas me avisas

Saludos...


  • 0

#3 genriquez

genriquez

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 539 mensajes
  • LocationCali, Colombia

Escrito 30 junio 2016 - 06:49

Existe una pequeña variación en Delphi para el manejo de Listas,  que en esencia hace lo mismo, pero resulta muy productivo en muchos casos.

 

 

1. En los uses adicionas System.Generics.Collections.

 

2.  Cambiamos la clase TObjectList, por la TDictionary, también existe en el mismo esquema el TList, y el TObjectList

 

Quedaría más o menos así.


php
  1. var
  2.    listaPersona: TDictionary<String, TPersona>;
  3.    t1, t2: TPersona;
  4.    R : TPersona;
  5.  
  6.  
  7. begin
  8.    t1 := TPersona.create('jose', 'garcia', casado, 'policia',
  9. 'azul 1', 'beta');
  10.    t2 := TPersona.create('luis', 'villega', soltero,
  11. 'cocinero', 'azul 1', 'alfa');
  12.    listaPersona := TDictionary<String,
  13. TPersona>(True);
  14.    listaPersona.Add(t1.nombre, T1);
  15.    listaPersona.Add(t2.nombre, t2);
  16.    for R in listaPersona.Values do
  17.       WriteLn(R.nombre);
  18.    listaPersona.Free;
  19.    ReadLn;
  20.  


  • 0

#4 sir.dev.a.lot

sir.dev.a.lot

    Advanced Member

  • Miembros
  • PipPipPip
  • 545 mensajes
  • Location127.0.0.1

Escrito 11 julio 2016 - 04:24

Hola, con esto mi aporte sencillo, para un tipo de Agenda.

 

Defines esto debajo de donde estan todas la unidades, y tambien entre la declaracion del Formulario  

 

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

 

//Tu tipo Record

 

  TForm1 = class(TForm)


delphi
  1. type
  2. recordtype=record
  3. no :string[5];
  4. name :string[20];
  5. address1 :string[40];
  6. address2 :string[40];
  7. telephone :string[15];
  8. fax :string[15];
  9. mail :string[40];
  10. city :string[15];
  11. country :string[15];
  12. end;

Ahora vamos a la seccion de Variables


delphi
  1. qfile:file of recordtype;
  2. qfile1:file of recordtype;
  3. qrecord:recordtype;

al Crear el Formulario, en este caso Form1


delphi
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3. Edit1.Text:='';
  4. Edit2.Text:='';
  5. Edit3.Text:='';
  6. Edit4.Text:='';
  7. Edit5.Text:='';
  8. Edit7.Text:='';
  9. Edit8.Text:='';
  10. Edit9.Text:='';
  11. Edit10.Text:='';
  12.  
  13. ASSIGNFILE(qfile,'c:\personal.txt');
  14. {$I-}
  15. Reset(qfile);
  16. {$I+}
  17. IF IORESULT <> 0 THEN REWRITE(qfile);
  18.  
  19. end;

para crear un nuevo Registro


delphi
  1. procedure TForm1.newrecClick(Sender: TObject);
  2. var
  3. warning:string;
  4. begin
  5. qrecord.no :=Edit1.Text;
  6. qrecord.name :=Edit2.Text;
  7. qrecord.address1 :=Edit3.Text;
  8. qrecord.address2 :=Edit4.Text;
  9. qrecord.telephone :=Edit5.Text;
  10. qrecord.fax :=Edit7.Text;
  11. qrecord.mail :=Edit8.Text;
  12. qrecord.city :=Edit9.Text;
  13. qrecord.country :=Edit10.Text;
  14.  
  15. if Edit1.Text = '' then
  16. begin
  17. warning:='Record no empty';
  18. showmessage(warning);
  19. end
  20.  
  21. else
  22.  
  23. if messagedlg('New record write to file',
  24. mtinformation,[mbyes,mbno],0)=mryes then
  25.  
  26. begin
  27.  
  28. seek(qfile,filesize(qfile));
  29. write(qfile,qrecord);
  30.  
  31. end;
  32. Edit1.Text:='';
  33. Edit2.Text:='';
  34. Edit3.Text:='';
  35. Edit4.Text:='';
  36. Edit5.Text:='';
  37. Edit7.Text:='';
  38. Edit8.Text:='';
  39. Edit9.Text:='';
  40. Edit10.Text:='';
  41. Edit1.SetFocus;
  42. end;

Buscar un Registro, en este caso usamos el Edit1


delphi
  1. procedure TForm1.searchrecClick(Sender: TObject);
  2. var
  3. i:integer;
  4. begin
  5. if edit1.Text<>''then
  6. if filesize(qfile)<>0 then
  7. for i:= 0 to filesize(qfile)-1 do
  8. begin
  9. seek(qfile,i);
  10. read(qfile,qrecord);
  11. if filesize(qfile)=0 then close;
  12. if qrecord.no=Edit1.Text then
  13. begin
  14. Edit2.Text:=qrecord.name;
  15. Edit3.Text:=qrecord.address1;
  16. Edit4.Text:=qrecord.address2;
  17. Edit5.Text:=qrecord.telephone;
  18. Edit7.Text:=qrecord.fax;
  19. Edit8.Text:=qrecord.mail;
  20. Edit9.Text:=qrecord.city;
  21. Edit10.Text:=qrecord.country;
  22. end;
  23. end;
  24. end;

Editar el Registro


delphi
  1. procedure TForm1.editrecClick(Sender: TObject);
  2. begin
  3. qrecord.no := Edit1.Text;
  4. qrecord.name := Edit2.Text;
  5. qrecord.address1 := Edit3.Text;
  6. qrecord.address2 := Edit4.Text;
  7. qrecord.telephone := Edit5.Text;
  8. qrecord.fax := Edit7.Text;
  9. qrecord.mail := Edit8.Text;
  10. qrecord.city := Edit9.Text;
  11. qrecord.country := Edit10.Text;
  12.  
  13. if edit1.Text='' then
  14. MessageDlg('Record no empty..!', mtInformation,
  15. [mbOk], 0 );
  16.  
  17.  
  18. begin
  19.  
  20. if edit1.text<>'' then if messagedlg('Edit record and write to file..!', mtinformation,[mbyes,mbno],0)=mryes then
  21.  
  22. write(qfile,qrecord);
  23. Edit1.Text:='';
  24. Edit2.Text:='';
  25. Edit3.Text:='';
  26. Edit4.Text:='';
  27. Edit5.Text:='';
  28. Edit7.Text:='';
  29. Edit8.Text:='';
  30. Edit9.Text:='';
  31. Edit10.Text:='';
  32. Edit1.SetFocus;
  33.  
  34. end;
  35. end;

Eliminar o Remover el Registro


delphi
  1. procedure TForm1.delrecClick(Sender: TObject);
  2. var
  3. a:integer;
  4. begin
  5.  
  6. ASSIGNFILE(qfile1,'c:\temp.txt');
  7. REWRITE(qfile1);
  8.  
  9. if Edit1.Text='' then
  10.  
  11. begin
  12.  
  13. if messagedlg('Recorde no empty..?',
  14. mtinformation,[mbyes,mbno],0)=mryes then
  15.  
  16. form1.Close;
  17. end;
  18.  
  19. begin
  20. for a:=0 to filesize(qfile)-1 do
  21. begin
  22. seek(qfile,a);
  23. read(qfile,qrecord);
  24. if qrecord.no <> Edit1.Text
  25. then
  26. write (qfile1,qrecord);
  27. end;
  28. end;
  29. closefile(qfile);
  30. closefile(qfile1);
  31. deletefile('c:\personal.txt');
  32. renamefile('c:\temp.txt','c:\personal.txt');
  33. Edit1.Text:='';
  34. Edit2.Text:='';
  35. Edit3.Text:='';
  36. Edit4.Text:='';
  37. Edit5.Text:='';
  38. Edit7.Text:='';
  39. Edit8.Text:='';
  40. Edit9.Text:='';
  41. Edit10.Text:='';
  42. Edit1.SetFocus;
  43. end;

Espero lo sirva.

 

Saludos!


  • 0




IP.Board spam blocked by CleanTalk.