DICAS

Visite a biblioteca de dicas da comunidade.

Saiba mais

ARTIGOS

Abordagens detalhadas sobre assuntos diversos.

Saiba mais

INICIANTES

Aprenda a programar de um modo simples e fácil.

Saiba mais

DOWNLOADS

Acesse os materiais exclusivos aos membros.

Saiba mais
voltar

Mabreu

Respostas no Fórum

Visualizando 2 posts - 1 até 2 (de 2 do total)
  • Autor
    Posts
  • em resposta a: Erro ao validar login #3161
    Mabreu
    Participante

    Minha Unit de Login tá assim:

    unit U_Login;

    interface

    uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Mask, Vcl.StdCtrls, Vcl.ExtCtrls,
    Vcl.Imaging.pngimage, System.ImageList, Vcl.ImgList, UniProvider,
    SQLServerUniProvider, Data.DB, MemDS, DBAccess, Uni,UCBase, U_DM,
    UCDataConnector, UCFireDACConn, UCSettings;

    type
    TFrm_Login = class(TForm)
    Button1: TButton;
    Button2: TButton;
    LinkLabel1: TLinkLabel;
    Image1: TImage;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    ValorNome: TEdit;
    ValorSenha: TEdit;
    ImageList1: TImageList;
    DataSource1: TDataSource;
    SQLServerUniProvider1: TSQLServerUniProvider;
    UniQuery1: TUniQuery;
    UserControl1: TUserControl;
    UCSettings1: TUCSettings;
    UCControls1: TUCControls;
    UCFireDACConn1: TUCFireDACConn;
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure ValorSenhaExit(Sender: TObject);
    procedure UserControl1CustomLoginForm(Sender: TObject;
    var CustomForm: TCustomForm);

    private
    FUserControl: TUserControl;
    procedure SetUserControl(const Value: TUserControl);

    public
    fecha: Boolean;
    property UserControl: TUserControl read FUserControl write SetUserControl;
    Function GetStateK (Key: integer): boolean;
    end;

    var
    Frm_Login: TFrm_Login;

    implementation

    {$R *.dfm}

    procedure TFrm_Login.Button1Click(Sender: TObject);
    begin
    if FUserControl.VerificaLogin(ValorNome.Text, ValorSenha.Text) = 0 then
    begin
    ShowMessage(‘Logado’);
    end
    else
    begin
    // erro login
    end;
    end;

    procedure TFrm_Login.Button2Click(Sender: TObject);
    begin
    Application.Terminate;
    end;

    procedure TFrm_Login.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    If Not fecha Then
    Action := caNone
    Else
    Action := caFree;
    end;

    procedure TFrm_Login.FormKeyDown(Sender: TObject; var Key: Word;
    Shift: TShiftState);
    begin
    If GetStateK (VK_LMENU) And (Key = VK_F4) Then
    fecha := False;
    end;

    procedure TFrm_Login.FormShow(Sender: TObject);
    begin
    ValorNome.SetFocus;
    end;

    function TFrm_Login.GetStateK(Key: integer): boolean;
    begin
    Result := Odd (GetKeyState (Key));
    end;

    procedure TFrm_Login.SetUserControl(const Value: TUserControl);
    begin
    FUserControl := Value;
    end;

    procedure TFrm_Login.UserControl1CustomLoginForm(Sender: TObject;
    var CustomForm: TCustomForm);
    begin
    CustomForm := TFrm_Login.Create(Application);
    TFrm_Login(CustomForm).UserControl := Self.UserControlMain;
    end;

    procedure TFrm_Login.ValorSenhaExit(Sender: TObject);
    begin
    Button1.setfocus;
    end;

    end.

    E a de Principal:

    unit Unit1;

    interface

    uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
    FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf,
    FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
    FireDAC.Phys, FireDAC.VCLUI.Wait, Data.DB, FireDAC.Comp.Client,
    FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
    dxGDIPlusClasses, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.Menus, FireDAC.Comp.DataSet,
    FireDAC.Comp.UI, FireDAC.Phys.MySQL, FireDAC.Phys.MySQLDef, UCSettings, UCBase,
    UCDataConnector, UCFireDACConn, U_DM, U_Login;

    type
    TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Cadastros1: TMenuItem;
    Pesquisas1: TMenuItem;
    Relatrios1: TMenuItem;
    Configuraes1: TMenuItem;
    Ajuda1: TMenuItem;
    Sair1: TMenuItem;
    Usurios1: TMenuItem;
    CriarConta1: TMenuItem;
    AlterarSenha1: TMenuItem;
    LogOff1: TMenuItem;
    BancodeDados1: TMenuItem;
    StatusBar1: TStatusBar;
    Image1: TImage;
    UserControlMain: TUserControl;
    UCFireDACConn1: TUCFireDACConn;

    private
    FUserControl: TUserControl;
    procedure SetUserControl(const Value: TUserControl);
    property UserControl: TUserControl read FUserControl write SetUserControl;

    public

    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    { TForm1 }

    procedure TForm1.SetUserControl(const Value: TUserControl);
    begin
    FUserControl := Value;
    end;

    em resposta a: Erro ao validar login #3160
    Mabreu
    Participante

    No form de Login tem que ter um componente Usercontrol1 também?

Visualizando 2 posts - 1 até 2 (de 2 do total)

Ir ao topo
© 2024 Infus Soluções em Tecnologia - Todos os Direitos Reservados