domingo, 29 de março de 2020

C++ builder - usuário e senha

Sempre vejo iniciantes em linguagem C ou C++,
querendo utilizar blbliotecas antigas em plataformas
modernas, não sabem a dor de cabeça que estão
semeando a si mesmos; Primeiro porque estas
bibliotecas já eram bastante limitadas,
para os sistemas onde foram criadas imaginem
agora com os avanços que estes sistemas receberam,
sei bem os problemas que arrumei quando tentei utilizá-las.
O C++ Builder é uma excelente ferramenta para criação
tanto de jogos como para programas em desktops,
mobile e web, e eu ainda o coloco acima do Qt,
Porque conheço os dois e posso opinar.
Neste programinha, mostro um exemplo de sistema de login,
mas existem mil maneiras de fazer e personalizar isto,
ainda mais utilizando uma IDE deste nível,
acompanhem no vídeo por favor:




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

#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 __fastcall TForm1::Informe ( TObject *Sender ) {
    Canvas -> Font-> Style = TFontStyles ( ) << fsItalic;
    Canvas -> Font -> Size = 11;
    Canvas -> Font -> Name = "Arial";
    Canvas -> Font -> Color = clBlack;
    Canvas -> TextOut ( 160, 240, "Por: " );
    Canvas -> Font -> Color = clRed;
    Canvas -> TextOut ( 200, 240, "Samuel Lima" );
    Canvas -> Font -> Color = clBlack;
    Canvas -> TextOut ( 160, 255, "sa_sp10@hotmail.com" );
}
 // ---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject* Sender ) {
     Bevel1 -> Height = 170;
     Bevel1 -> Width = 210;
     Bevel1 -> Left = 145;
     Bevel1 -> Top = 55;

     Panel1 -> Font -> Size = 12;
     Panel1 -> Font -> Color = clRed;
     Panel1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
     Panel1 -> Width = 175;
     Panel1 -> Height = 20;
     Panel1 -> Left = 160;
     Panel1 -> Top = 200;
     Panel1 -> Caption = "Usuário e senha";

     Panel2 -> Font -> Size = 14;
     Panel2 -> Font -> Color = clRed;
     Panel2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
     Panel2 -> Width = 390;
     Panel2 -> Height = 20;
     Panel2 -> Left = 110;
     Panel2 -> Top = 15;
     Panel2 -> Caption = "C++ BUILDER - USUÁRIO E SENHA II";

     Edit1 -> SetFocus ( );
     Edit1 -> Font -> Size = 12;
     Edit1 -> Font -> Color = clRed;
     Edit1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
     Edit1 -> Width = 90;
     Edit1 -> Height = 20;
     Edit1 -> Left = 240;
     Edit1 -> Top = 70;

     //Edit1 -> SetFocus ( );
     Edit2 -> Font -> Size = 12;
     Edit2 -> Font -> Color = clBlack;
     Edit2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
     Edit2 -> Width = 90;
     Edit2 -> Height = 20;
     Edit2 -> Left = 240;
     Edit2 -> Top = 100;

     //Edit1 -> SetFocus ( );
     Edit3 -> Font -> Size = 12;
     Edit3 -> Font -> Color = clBlack;
     Edit3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
     Edit3 -> Width = 90;
     Edit3 -> Height = 20;
     Edit3 -> Left = 240;
     Edit3 -> Top = 130;

    Label1 -> Font -> Size = 12;
    Label1 -> Font-> Style = TFontStyles ( ) << fsItalic ;
    Label1 -> Font -> Color = clBlack;
    Label1 -> Width = 130;
    Label1 -> Height = 20;
    Label1 -> Left = 160;
    Label1 -> Top = 70;
    Label1 -> Caption = "Usuário: ";

    Label2 -> Font -> Size = 12;
    Label2 -> Font-> Style = TFontStyles ( ) << fsItalic ;
    Label2 -> Font -> Color = clBlue;
    Label2 -> Width = 130;
    Label2 -> Height = 20;
    Label2 -> Left = 160;
    Label2 -> Top = 100;
    Label2 -> Caption = "Senha: ";

    Label3 -> Font -> Size = 12;
    Label3 -> Font-> Style = TFontStyles ( ) << fsItalic ;
    Label3 -> Font -> Color = clRed;
    Label3 -> Width = 130;
    Label3 -> Height = 20;
    Label3 -> Left = 160;
    Label3 -> Top = 130;
    Label3 -> Caption = "Confirma: ";

    BitBtn1 -> Font -> Size = 12;
    BitBtn1 -> Font -> Color = clBlue;
    BitBtn1 -> Font -> Style = TFontStyles ( ) << fsItalic;
    BitBtn1 -> Top = 160;
    BitBtn1 -> Left = 160;
    BitBtn1 -> Height = 23;
    BitBtn1 -> Width = 40;

    BitBtn2 -> Font -> Size = 12;
    BitBtn2 -> Font -> Color = clBlue;
    BitBtn2 -> Font -> Style = TFontStyles ( ) << fsItalic;
    BitBtn2 -> Top = 160;
    BitBtn2 -> Left = 290;
    BitBtn2 -> Height = 23;
    BitBtn2 -> Width = 40;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnPaint ( TObject *Sender ) {
      Canvas -> Font -> Size = 14;
      Canvas -> Font -> Name = "Arial";
      Canvas -> Pen -> Width = 10;
      Canvas -> Rectangle ( 05, 05, 595, 295 );
      Canvas -> Pen -> Color = clBlue;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
Label_Manual ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
    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 -> Font -> Color = clBlue;
        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 -> Font -> Color = clGreen;
            Panel1 -> Caption = "Senhas desiguais";
            Edit2 -> Clear ( );
            Edit3 -> Clear ( );
            Edit2 -> SetFocus ( );
        } else {
            Panel1 -> Font -> Color = clBlack;
            Panel1 -> Caption = "Login efetuado";
        }
    }
    Informe ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(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>
#include <Vcl.Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TPanel *Panel1;
    TEdit *Edit1;
    TEdit *Edit2;
    TEdit *Edit3;
    TPanel *Panel2;
    TBitBtn *BitBtn1;
    TBitBtn *BitBtn2;
    TBevel *Bevel1;
    void __fastcall Label_Manual ( TObject* Sender );
    void __fastcall Informe ( TObject *Sender );
    void __fastcall OnPaint(TObject *Sender);
    void __fastcall FormShow(TObject *Sender);
    void __fastcall BitBtn1Click(TObject *Sender);
    void __fastcall BitBtn2Click(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 II'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesigned
  OnPaint = OnPaint
  OnShow = FormShow
  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 Bevel1: TBevel
    Left = 526
    Top = 193
    Width = 43
    Height = 25
  end
  object Panel1: TPanel
    Left = 526
    Top = 47
    Width = 43
    Height = 23
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -19
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 0
  end
  object Edit1: TEdit
    Left = 526
    Top = 84
    Width = 43
    Height = 27
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 1
  end
  object Edit2: TEdit
    Left = 526
    Top = 117
    Width = 43
    Height = 27
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    PasswordChar = '*'
    TabOrder = 2
  end
  object Edit3: TEdit
    Left = 526
    Top = 150
    Width = 43
    Height = 27
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    PasswordChar = '*'
    TabOrder = 3
  end
  object Panel2: TPanel
    Left = 526
    Top = 17
    Width = 43
    Height = 24
    Color = clWhite
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -24
    Font.Name = 'Tahoma'
    Font.Style = [fsItalic]
    ParentBackground = False
    ParentFont = False
    TabOrder = 4
  end
  object BitBtn1: TBitBtn
    Left = 526
    Top = 235
    Width = 43
    Height = 25
    Caption = 'Ok'
    TabOrder = 5
    OnClick = BitBtn1Click
  end
  object BitBtn2: TBitBtn
    Left = 526
    Top = 266
    Width = 43
    Height = 25
    Caption = 'Sair'
    TabOrder = 6
    OnClick = BitBtn2Click
  end
end

Nenhum comentário:

Postar um comentário

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