Jump to content
mykos

ajuda!!!

Recommended Posts

mykos

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!!!

Share this post


Link to post
Share on other sites
NCS_One

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.

Share this post


Link to post
Share on other sites
NCS_One

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.