mykos Posted April 8, 2009 at 09:51 PM Report #255981 Posted April 8, 2009 at 09:51 PM boas pessoal!!! Na aula de programaçao, fizemos um exercicio que envolvia programaçao de formularios e base de dados, tinhamos que desenhar um formulario como era mostrado na imagem do exercico e liga-lo a base de dados..até ai tudo bem..fiz o exercicio todo e como acabei antes do resto do pessoal pus-me a explorar e queria que tipo quando carregasse no botao de inserir aparecesse uma mensagem a dizer que os dados foram inseridos e com um botao para fechar e ao carregar nesse botao fechasse a mensagem e limpasse os dados inseridos dos campos..a parte de aparecer a mensagem consegui fazer, mas nao consegui fazer a parte de limpar os campos.. alguém me dá uma ajuda?? pra quem quiser ver o codigo está aqui: unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls, mysql50conn, sqldb, db, unit2, unit3; type { TForm1 } TForm1 = class(TForm) Button1: TButton; ComboBox1: TComboBox; Datasource1: TDatasource; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; MainMenu1: TMainMenu; MenuItem1: TMenuItem; MenuItem2: TMenuItem; MenuItem3: TMenuItem; MySQL50Connection1: TMySQL50Connection; SQLQuery1: TSQLQuery; SQLTransaction1: TSQLTransaction; procedure Button1Click(Sender: TObject); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure Label3Click(Sender: TObject); procedure MenuItem3Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation { TForm1 } procedure TForm1.Label3Click(Sender: TObject); begin end; procedure TForm1.MenuItem3Click(Sender: TObject); begin form2.show; end; procedure TForm1.FormCreate(Sender: TObject); begin if mysql50connection1.connected then begin mysql50connection1.close; end; mysql50connection1.open; end; procedure TForm1.Button1Click(Sender: TObject); begin if sqlquery1.active then sqlquery1.close; sqlquery1.sql.text:='insert into t_alunos (numero, nome, curso, turma) values ("'+ edit1.text +'","'+ edit2.text +'","'+ combobox1.text+ '","'+ edit3.text + '")'; edit4.text := sqlquery1.sql.text; sqlquery1.execsql; sqlquery1.close; form3.show; end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); begin mysql50connection1.close; end; initialization {$I unit1.lrs} end. unit Unit2; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, DBGrids, mysql50conn, sqldb, db; type { TForm2 } TForm2 = class(TForm) Button1: TButton; Button2: TButton; Datasource1: TDatasource; DBGrid1: TDBGrid; Edit1: TEdit; Label1: TLabel; MySQL50Connection1: TMySQL50Connection; Panel1: TPanel; SQLQuery1: TSQLQuery; SQLTransaction1: TSQLTransaction; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form2: TForm2; implementation { TForm2 } procedure TForm2.Button1Click(Sender: TObject); begin if sqlquery1.active then sqlquery1.close; sqlquery1.sql.text:= 'select count(*) as numero from t_alunos'; sqlquery1.open; edit1.text:=sqlquery1.fieldbyname ('numero').asstring; sqlquery1.close; if sqlquery1.active then sqlquery1.close; sqlquery1.sql.text:= 'select * from t_alunos'; sqlquery1.open; dbgrid1.show; end; procedure TForm2.Button2Click(Sender: TObject); begin form2.close; end; initialization {$I unit2.lrs} end. unit Unit3; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm3 } TForm3 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); procedure Label1Click(Sender: TObject); private { private declarations } public { public declarations } end; var Form3: TForm3; implementation { TForm3 } procedure TForm3.Label1Click(Sender: TObject); begin end; procedure TForm3.Button1Click(Sender: TObject); begin Form3.close; end; initialization {$I unit3.lrs} end. Obrigado a todos!!!
NCS_One Posted April 8, 2009 at 11:18 PM Report #256002 Posted April 8, 2009 at 11:18 PM Boas. Sabes quais os campos que tens de apagar nao sabes? Entao imagina que 1 deles é o Edit1, entao fazes : Edit1.Text := ""; Se a vida te voltar as costas aproveita e apalpa-lhe o cu.
mykos Posted April 8, 2009 at 11:21 PM Author Report #256004 Posted April 8, 2009 at 11:21 PM sim..mas como é que faço isso do form3 para o form1??
NCS_One Posted April 8, 2009 at 11:43 PM Report #256006 Posted April 8, 2009 at 11:43 PM Experimenta : Form1.Edit1.Text := ""; O melhor era fazeres um procedimento no TForm1, por exemplo chamado LimpaCampos e depois era so : Form1.LimpaCampos(); e no LimpaCampos é que tinhas : Edit1.Text := ""; Se a vida te voltar as costas aproveita e apalpa-lhe o cu.
mykos Posted April 8, 2009 at 11:46 PM Author Report #256008 Posted April 8, 2009 at 11:46 PM ok..obrigado pela ajuda!!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now