sábado, 9 de novembro de 2019

Preenchendo uma matriz de string com TEdit III

Aqui está um exemplo de como preencher
uma matriz de string usando o objeto TEdit
do C++ builder.
Como acrescentei vários detalhes para
melhorar a visualização, o código
ficou um pouco extenso.




//Preenchendo uma matriz de string com TEdit III
#include <vcl.h>
#pragma hdrstop

#include "Unit1.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 -> Name = "Garamond";
    Canvas -> Font -> Color = clBlack;
    Canvas -> TextOut ( 200, 190, "Por: " );
    Canvas -> Font -> Color = clRed;
    Canvas -> TextOut ( 240, 190, "Samuel Lima" );
    Canvas -> Font -> Color = clBlack;
    Canvas -> TextOut ( 200, 210, "sa_sp10@hotmail.com" );
    Canvas -> Font -> Name = "Garamond";
    BitBtn2 -> Visible = true;
}

//---------------------------------------------------------------------------
 int __fastcall TForm1::Contador ( TObject *Sender ) {
     static int n = t;
     return n + 2;
}
//---------------------------------------------------------------------------
 int __fastcall TForm1::Contador_Negativo ( TObject *Sender ) {
     static int n = t;
     return n--;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Button_Manual ( TObject *Sender ) {
    Lbl -> Parent = Form1;
    Lbl -> Font -> Size = 12;
    Lbl -> Font -> Color = clBlue;
    Lbl -> Width = 130;
    Lbl -> Height = 20;
    Lbl -> Left = 164;
    Lbl -> Top = 82;
    if ( x == false )
    Lbl -> Caption = "Total de palavras";
    Lbl -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FuncAtual ( TObject *Sender ) {
       if ( i == u ) {
           i = i - 2;
       }
       Lbl -> Left = 164;
       Lbl -> Caption = StrToInt ( i );
       Lbl -> Caption = Lbl -> Caption + "ª";
       Lbl -> Caption = Lbl -> Caption + " Palavra ";
    if ( i == 1 ) {
     MessageBeep ( 0 );
     Label_Button_Manual ( Sender );
     Form1 -> Edit1 -> Width = 80;
     Form1 -> Edit1 -> Height = 20;
     Form1 -> Edit1 -> Left = 250;
     Form1 -> Edit1 -> Top = 82;
       Lbl -> Left = 164;
       Lbl -> Caption = StrToInt ( i );
       Lbl -> Caption = Lbl -> Caption + "ª";
       Lbl -> Caption = Lbl -> Caption + " Palavra ";
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1Paint ( TObject *Sender )
{
    BitBtn2 -> Visible = false;
    Label_Button_Manual ( Sender );
    if ( x == false ) {
     Edit1 -> Width = 30;
     Edit1 -> Height = 20;
     Edit1 -> Left = 300;
     Edit1 -> Top = 82;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click ( TObject *Sender )
{
    i++;
    int u;
    String str;
    String st;
    do {
    t = Edit1 -> Text.ToIntDef ( 0 );
    u = Contador ( Sender );
    *nomes [ i ] = Edit1 -> Text;
   if ( i == u - 1 ) {
     y = true;
   Beep ( 500, 500 );
   for ( i = 2; i < u; i++ ) {
   st += i - 1;
   st += "ª";
   st += "\n";
   //st += " ";
   str += " ";
   str += *nomes [ i ];

   Label3 -> Top = 64;
   Label3 -> Left = 220;
   Label3 -> Caption = st;

   Label1 -> Top = 64;
   Label1 -> Caption = str;
   str += "\n";
   }
   }
   FuncAtual ( Sender );
     break;
    }while ( i == u );
    Edit1 -> Text = " ";
    if ( y == false ) {
      Edit1 -> SetFocus ( );
    }
    else {
     Edit1 -> Visible = false;
     Lbl -> Caption = " ";
     Informe ( Sender );
    }
    v = Contador_Negativo ( Sender );
    Label2 -> Caption = StrToInt ( v );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint ( TObject *Sender )
{
  Canvas -> Font -> Size = 14;
  Canvas -> Font -> Name = "Garamond";
  Canvas -> Pen -> Color = clGray;
  Canvas -> Pen -> Width = 10;
  Canvas -> Rectangle ( 05, 05, 595, 295 );
  SetTextColor ( Canvas -> Handle, RGB ( 255, 25, 2 ) );
  Canvas -> TextOut ( 135, 12, "C++ BUILDER - MATRIZ DE STRING III" );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
exit ( 0);
}
//---------------------------------------------------------------------------


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>

#include <Classes.hpp>
#include <Controls.hpp>
#include <Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TEdit *Edit1;
    TPaintBox *PaintBox1;
    TBitBtn *BitBtn1;
    TLabel *Label1;
    TLabel *Lbl;
    TBitBtn *BitBtn2;
    TLabel *Label2;
    TLabel *Label3;
    void __fastcall FuncAtual ( TObject *Sender );
    void __fastcall Label_Button_Manual ( TObject *Sender );
    void __fastcall PaintBox1Paint(TObject *Sender);
    int __fastcall Contador ( TObject *Sender );
    int __fastcall Contador_Negativo ( TObject *Sender );
    void __fastcall BitBtn1Click(TObject *Sender);
    void __fastcall FormPaint(TObject *Sender);
    void __fastcall Informe ( TObject *Sender );
    void __fastcall BitBtn2Click(TObject *Sender);
private:    // User declarations
    bool y = false;
    bool x = false;
    String nomes [ 60 ] [ 16 ];
    int i, t, u, v;
public:        // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


object Form1: TForm1
  Left = 515
  Top = 206
  Caption = 'C++ BUILDER - MATRIZ DE STRING III'
  ClientHeight = 300
  ClientWidth = 600
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesigned
  OnPaint = FormPaint
  PixelsPerInch = 96
  TextHeight = 13
  object PaintBox1: TPaintBox
    Left = 512
    Top = 231
    Width = 41
    Height = 42
    OnPaint = PaintBox1Paint
  end
  object Label1: TLabel
    Left = 248
    Top = 120
    Width = 5
    Height = 19
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlue
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Lbl: TLabel
    Left = 64
    Top = 168
    Width = 3
    Height = 13
  end
  object Label2: TLabel
    Left = 512
    Top = 40
    Width = 32
    Height = 56
    Font.Charset = ANSI_CHARSET
    Font.Color = clRed
    Font.Height = -53
    Font.Name = 'alarm clock'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label3: TLabel
    Left = 16
    Top = 176
    Width = 5
    Height = 19
    Font.Charset = ANSI_CHARSET
    Font.Color = clRed
    Font.Height = -17
    Font.Name = 'Arial'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 232
    Top = 68
    Width = 121
    Height = 21
    TabOrder = 0
  end
  object BitBtn1: TBitBtn
    Left = 256
    Top = 248
    Width = 75
    Height = 25
    Caption = 'OK'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 1
    OnClick = BitBtn1Click
  end
  object BitBtn2: TBitBtn
    Left = 256
    Top = 248
    Width = 75
    Height = 25
    Caption = 'Sair'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 2
    OnClick = BitBtn2Click
  end
end

Nenhum comentário:

Postar um comentário

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