asdbernardo
22-09-2011, 18:03:27
Buenas tardes, foristas!
Ante todo un cordial saludo a todos..
me estoy iniciando en el delphi ( vengo de visual basic ) y tengo varias dudas que se me vienen presentando en mi proyecto, estoy haciendo un programa cliente servidor, en mysql y delphi 2010, pero tengo varios problemitas en cuanto a los Violation access, he estado leyendo y a lo mejor puede ser porque no me va muy bien con eso de que hay que liberar y destruir los form .. entonces a ver
tengo 3 pantallas, una es un login, la siguiente es principal y la siguiente es agencia, seria algo asi:
Login
Principal > aca tiene un mainmenu donde al darle click a Agencia se despliegan otro menus y en ese menu esta un menuitem que selecciona el formulario Agencia y lo muestro con un .show y lo declaro en uses Agencia.
pero me salta un error de violation access y lo he probado en diferentes maquinas con delphi 2010 y sigue saltando ese error, posteare el codigo para que lo vean
source project
program Project1;
uses
Forms,
Controls,
Login in 'Login.pas' {frmLogin},
Principal in 'Principal.pas' {frmPrincipal},
Agencia in 'Agencia.pas' {frmAgencia};
{$R *.res}
var
Respuesta: integer;
begin
Application.Initialize;
Application.Title := 'WB System';
frmLogin := TfrmLogin.Create(Application);
frmprincipal := Tfrmprincipal.Create(Application);
try
Respuesta := frmLogin.ShowModal;
if Respuesta = mrOK then
begin
Application.CreateForm(TfrmPrincipal, frmPrincipal);
Application.CreateForm(TfrmAgencia, frmAgencia);
Application.CreateForm(TfrmLogin, frmLogin);
Application.Run;
end;
finally
frmLogin.Free;
end;
end.
code login.
unit Login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DBCtrls, UniProvider, MySQLUniProvider, DB, DBAccess,
Uni, MemDS;
type
TfrmLogin = class(TForm)
UniConnection1: TUniConnection;
UniTable1: TUniTable;
UniDataSource1: TUniDataSource;
MySQLUniProvider1: TMySQLUniProvider;
Button1: TButton;
qry: TUniQuery;
txtusu: TEdit;
txtpass: TEdit;
qryuser_login: TStringField;
qryuser_password: TStringField;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
lblintentos: TLabel;
lblverifique: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure txtusuKeyPress(Sender: TObject; var Key: Char);
procedure txtpassKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmLogin: TfrmLogin;
nintentos: integer;
veces: integer;
implementation
uses Principal;
{$R *.dfm}
procedure TfrmLogin.Button1Click(Sender: TObject);
begin
qry.SQL.Clear;
qry.SQL.Add(' select user_login');
qry.SQL.Add(' , user_Password');
qry.SQL.Add(' from Login');
qry.SQL.Add(' where user_login = Upper(:UserLogin)');
qry.SQL.Add(' and ');
qry.SQL.Add(' user_password = (:UserPassword)');
qry.Params[0].Value := UpperCase(Trim(txtusu.Text));
qry.Params[1].Value := Trim(txtpass.Text);
qry.Open;
if qry.RecordCount > 0 then
begin
frmprincipal.Show;
frmlogin.Hide;
end
else
begin
nIntentos := nIntentos + 1 ; {Intentos del login}
veces := 3; {Veces limite de login}
lblIntentos.Visible := true;
lblIntentos.Caption := 'Intentos Restantes: ' + inttostr(veces-nIntentos);
lblVerifique.Caption := 'Login Invalido, Verifique!';
if (nIntentos < veces) then
begin
txtusu.Text := '';
txtpass.Text :='';
txtusu.SetFocus;
end
else if (nIntentos = veces) then
begin
txtusu.Text := '';
txtpass.Text :='';
txtusu.SetFocus;
frmLogin.ModalResult := mrCancel;
Application.MessageBox( 'Maximo de Intentos, Sera notificado al Administrador',
'Acceso denegado', MB_ICONSTOP );
end;
end;
end;
procedure TfrmLogin.Button2Click(Sender: TObject);
begin
close;
end;
procedure TfrmLogin.txtpassKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then { if it's an enter key }
begin
Key := #0; { eat enter key }
Perform(WM_NEXTDLGCTL, 0, 0); { move to next control }
end
end;
procedure TfrmLogin.txtusuKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then { if it's an enter key }
begin
Key := #0; { eat enter key }
Perform(WM_NEXTDLGCTL, 0, 0); { move to next control }
end
end;
end.
y por ultimo el principal
unit Principal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, buttons , StdCtrls;
type
TfrmPrincipal = class(TForm)
MainMenu1: TMainMenu;
Archivo1: TMenuItem;
CerrarPrograma1: TMenuItem;
Agencias1: TMenuItem;
RegistrarAgencia1: TMenuItem;
RegistrarUsuario1: TMenuItem;
Loterias1: TMenuItem;
RegistrarAgencia2: TMenuItem;
ModificarAgencia1: TMenuItem;
Borrar1: TMenuItem;
Registrar1: TMenuItem;
Modificar1: TMenuItem;
Borrar2: TMenuItem;
procedure CerrarPrograma1Click(Sender: TObject);
procedure RegistrarAgencia2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmPrincipal: TfrmPrincipal;
implementation
uses agencia;
{$R *.dfm}
procedure TfrmPrincipal.CerrarPrograma1Click(Sender: TObject);
begin
application.Terminate;
end;
procedure TfrmPrincipal.RegistrarAgencia2Click(Sender: TObject);
begin
frmagencia.Show;
end;
end.
y pues agencia no tengo nada programado aun porque no me lo muestra y estoy con eso del violation access xD
unit Agencia;
interface
uses StdCtrls, Classes, Windows, Messages, SysUtils, Variants, Graphics, Forms,
Dialogs, Controls;
type
TfrmAgencia = class(TForm)
lblModuloAgencias: TLabel;
gbDatosAgencia: TGroupBox;
edtnombreagencia: TEdit;
edtresponsable: TEdit;
lblnombreagencia: TLabel;
lblresponsable: TLabel;
edtnumeroagencia: TEdit;
lblnroagencia: TLabel;
gblimiteventas: TGroupBox;
lblterminales: TLabel;
lbltriples: TLabel;
lblzodiacales: TLabel;
edtterminales: TEdit;
edttriples: TEdit;
edtzodiacales: TEdit;
btnaceptar: TButton;
btncancelar: TButton;
lblregistro: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmAgencia: TfrmAgencia;
implementation
{$R *.dfm}
end.
el error que me marca de violation es:
Access Violation at address 004AFBB6 in module 'project1.exe'. Read of Address 00000384
si alguno me puede guiar sobre evitar estos access violation en cuando a la llamado de formularios me gustaria mucho! saludos
Y gracias por su atencion a mi post!
Ante todo un cordial saludo a todos..
me estoy iniciando en el delphi ( vengo de visual basic ) y tengo varias dudas que se me vienen presentando en mi proyecto, estoy haciendo un programa cliente servidor, en mysql y delphi 2010, pero tengo varios problemitas en cuanto a los Violation access, he estado leyendo y a lo mejor puede ser porque no me va muy bien con eso de que hay que liberar y destruir los form .. entonces a ver
tengo 3 pantallas, una es un login, la siguiente es principal y la siguiente es agencia, seria algo asi:
Login
Principal > aca tiene un mainmenu donde al darle click a Agencia se despliegan otro menus y en ese menu esta un menuitem que selecciona el formulario Agencia y lo muestro con un .show y lo declaro en uses Agencia.
pero me salta un error de violation access y lo he probado en diferentes maquinas con delphi 2010 y sigue saltando ese error, posteare el codigo para que lo vean
source project
program Project1;
uses
Forms,
Controls,
Login in 'Login.pas' {frmLogin},
Principal in 'Principal.pas' {frmPrincipal},
Agencia in 'Agencia.pas' {frmAgencia};
{$R *.res}
var
Respuesta: integer;
begin
Application.Initialize;
Application.Title := 'WB System';
frmLogin := TfrmLogin.Create(Application);
frmprincipal := Tfrmprincipal.Create(Application);
try
Respuesta := frmLogin.ShowModal;
if Respuesta = mrOK then
begin
Application.CreateForm(TfrmPrincipal, frmPrincipal);
Application.CreateForm(TfrmAgencia, frmAgencia);
Application.CreateForm(TfrmLogin, frmLogin);
Application.Run;
end;
finally
frmLogin.Free;
end;
end.
code login.
unit Login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DBCtrls, UniProvider, MySQLUniProvider, DB, DBAccess,
Uni, MemDS;
type
TfrmLogin = class(TForm)
UniConnection1: TUniConnection;
UniTable1: TUniTable;
UniDataSource1: TUniDataSource;
MySQLUniProvider1: TMySQLUniProvider;
Button1: TButton;
qry: TUniQuery;
txtusu: TEdit;
txtpass: TEdit;
qryuser_login: TStringField;
qryuser_password: TStringField;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
lblintentos: TLabel;
lblverifique: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure txtusuKeyPress(Sender: TObject; var Key: Char);
procedure txtpassKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmLogin: TfrmLogin;
nintentos: integer;
veces: integer;
implementation
uses Principal;
{$R *.dfm}
procedure TfrmLogin.Button1Click(Sender: TObject);
begin
qry.SQL.Clear;
qry.SQL.Add(' select user_login');
qry.SQL.Add(' , user_Password');
qry.SQL.Add(' from Login');
qry.SQL.Add(' where user_login = Upper(:UserLogin)');
qry.SQL.Add(' and ');
qry.SQL.Add(' user_password = (:UserPassword)');
qry.Params[0].Value := UpperCase(Trim(txtusu.Text));
qry.Params[1].Value := Trim(txtpass.Text);
qry.Open;
if qry.RecordCount > 0 then
begin
frmprincipal.Show;
frmlogin.Hide;
end
else
begin
nIntentos := nIntentos + 1 ; {Intentos del login}
veces := 3; {Veces limite de login}
lblIntentos.Visible := true;
lblIntentos.Caption := 'Intentos Restantes: ' + inttostr(veces-nIntentos);
lblVerifique.Caption := 'Login Invalido, Verifique!';
if (nIntentos < veces) then
begin
txtusu.Text := '';
txtpass.Text :='';
txtusu.SetFocus;
end
else if (nIntentos = veces) then
begin
txtusu.Text := '';
txtpass.Text :='';
txtusu.SetFocus;
frmLogin.ModalResult := mrCancel;
Application.MessageBox( 'Maximo de Intentos, Sera notificado al Administrador',
'Acceso denegado', MB_ICONSTOP );
end;
end;
end;
procedure TfrmLogin.Button2Click(Sender: TObject);
begin
close;
end;
procedure TfrmLogin.txtpassKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then { if it's an enter key }
begin
Key := #0; { eat enter key }
Perform(WM_NEXTDLGCTL, 0, 0); { move to next control }
end
end;
procedure TfrmLogin.txtusuKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then { if it's an enter key }
begin
Key := #0; { eat enter key }
Perform(WM_NEXTDLGCTL, 0, 0); { move to next control }
end
end;
end.
y por ultimo el principal
unit Principal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, buttons , StdCtrls;
type
TfrmPrincipal = class(TForm)
MainMenu1: TMainMenu;
Archivo1: TMenuItem;
CerrarPrograma1: TMenuItem;
Agencias1: TMenuItem;
RegistrarAgencia1: TMenuItem;
RegistrarUsuario1: TMenuItem;
Loterias1: TMenuItem;
RegistrarAgencia2: TMenuItem;
ModificarAgencia1: TMenuItem;
Borrar1: TMenuItem;
Registrar1: TMenuItem;
Modificar1: TMenuItem;
Borrar2: TMenuItem;
procedure CerrarPrograma1Click(Sender: TObject);
procedure RegistrarAgencia2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmPrincipal: TfrmPrincipal;
implementation
uses agencia;
{$R *.dfm}
procedure TfrmPrincipal.CerrarPrograma1Click(Sender: TObject);
begin
application.Terminate;
end;
procedure TfrmPrincipal.RegistrarAgencia2Click(Sender: TObject);
begin
frmagencia.Show;
end;
end.
y pues agencia no tengo nada programado aun porque no me lo muestra y estoy con eso del violation access xD
unit Agencia;
interface
uses StdCtrls, Classes, Windows, Messages, SysUtils, Variants, Graphics, Forms,
Dialogs, Controls;
type
TfrmAgencia = class(TForm)
lblModuloAgencias: TLabel;
gbDatosAgencia: TGroupBox;
edtnombreagencia: TEdit;
edtresponsable: TEdit;
lblnombreagencia: TLabel;
lblresponsable: TLabel;
edtnumeroagencia: TEdit;
lblnroagencia: TLabel;
gblimiteventas: TGroupBox;
lblterminales: TLabel;
lbltriples: TLabel;
lblzodiacales: TLabel;
edtterminales: TEdit;
edttriples: TEdit;
edtzodiacales: TEdit;
btnaceptar: TButton;
btncancelar: TButton;
lblregistro: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmAgencia: TfrmAgencia;
implementation
{$R *.dfm}
end.
el error que me marca de violation es:
Access Violation at address 004AFBB6 in module 'project1.exe'. Read of Address 00000384
si alguno me puede guiar sobre evitar estos access violation en cuando a la llamado de formularios me gustaria mucho! saludos
Y gracias por su atencion a mi post!