sábado, 26 de janeiro de 2019

C++ Builder - Usuário e Senha

O que estamos fazendo aqui, é comparando
duas Strings, ou sequência de caracteres,
A função compara duas variaveis AnsiString,
e neste caso não difere maiúscula de minúscula,
Se as sequências forem iguais,
temos um resultado verdadeiro, (True),
Se não forem iguais, falso é retornado,
a função usada é a Same Text ( str1, str2 );
E sua síntaxe: é esta abaixo:
bool __fastcall SameText(const AnsiString String1, const AnsiString String2);
Verifique a documentação do Embarcadero,
para mais detalhes.







//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "OnPaint.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner ) :
TForm ( Owner ) {
}
void Button1Click ( TObject *Sender );
//---------------------------------------------------------------------------
void __fastcall TForm1::OnPaint ( TObject *Sender ) {
Label1 -> Caption = "Usuário: ";
Label2 -> Caption = "Senha: ";
Label3 -> Caption = "Confirma: ";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
Panel2 -> Caption = "C++ BUILDER - USUÁRIO E SENHA";
String Usuario_1 = "Samuel";
String Usuario_2 = Edit1 -> Text;
Boolean Result_1 = SameText ( Usuario_1, Usuario_2 );
String Senha_1 = Edit2 -> Text;
String Senha_2 = Edit3 -> Text;
if ( Result_1 == False ) {
Panel1 -> Caption = "Usuário não confere";
Edit1 -> SetFocus ( );
Edit1 -> Clear ( );
} else {
Boolean Result_2 = SameText ( Senha_1, Senha_2 );
if ( Result_2 == False ) {
Panel1 -> Caption = "Senhas desiguais";
Edit2 -> Clear ( );
Edit3 -> Clear ( );
Edit2 -> SetFocus ( );
} else {
Panel1 -> Caption = "Login efetuado";
}
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click ( TObject *Sender ) {
Close ( );
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------

#ifndef OnPaintH
#define OnPaintH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TButton *Button1;
TButton *Button2;
TPanel *Panel1;
TEdit *Edit1;
TEdit *Edit2;
TEdit *Edit3;
TShape *Shape1;
TShape *Shape2;
TPanel *Panel2;
void __fastcall OnPaint(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


object Form1: TForm1
  Left = 342
  Top = 219
  Width = 616
  Height = 338
  AutoScroll = True
  Caption = 'C++ BUILDER - USU'#193'RIO E SENHA'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesigned
  OnPaint = OnPaint
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 149
    Top = 84
    Width = 6
    Height = 23
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -19
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Label2: TLabel
    Left = 149
    Top = 113
    Width = 6
    Height = 23
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -19
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Label3: TLabel
    Left = 149
    Top = 142
    Width = 6
    Height = 23
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -19
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Shape1: TShape
    Left = 0
    Top = 0
    Width = 600
    Height = 300
    Brush.Style = bsClear
    Pen.Width = 10
  end
  object Shape2: TShape
    Left = 128
    Top = 64
    Width = 249
    Height = 209
    Brush.Style = bsClear
    Pen.Color = clBlue
    Pen.Width = 3
    Shape = stRoundRect
  end
  object Button1: TButton
    Left = 149
    Top = 240
    Width = 57
    Height = 25
    Caption = 'Ok'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Panel1: TPanel
    Left = 149
    Top = 179
    Width = 212
    Height = 30
    Caption = 'Usu'#225'rio e Senha'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -19
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 1
  end
  object Edit1: TEdit
    Left = 240
    Top = 84
    Width = 121
    Height = 27
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 2
  end
  object Edit2: TEdit
    Left = 240
    Top = 118
    Width = 121
    Height = 27
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 3
  end
  object Edit3: TEdit
    Left = 240
    Top = 152
    Width = 121
    Height = 27
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 4
  end
  object Button2: TButton
    Left = 304
    Top = 240
    Width = 57
    Height = 25
    Caption = 'Sair'
    TabOrder = 5
    OnClick = Button2Click
  end
  object Panel2: TPanel
    Left = 88
    Top = 17
    Width = 425
    Height = 24
    Caption = 'C++ BUILDER - USU'#193'RIO E SENHA'
    Color = clWhite
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -24
    Font.Name = 'Tahoma'
    Font.Style = [fsItalic]
    ParentBackground = False
    ParentFont = False
    TabOrder = 6
  end
end

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.