quinta-feira, 13 de agosto de 2020

FMX - apagando string em matriz bidimensional

 Neste exemplo estamos mostrando como apagar string 
em uma matriz bidimensional.
e o melhor de tudo é que não estamos usando
nenhuma função especial para istp,
mesmo porque no C isto não existe, temos que criar
quase tudo na mão, mas eu não me importo,
somos fascinados por linguagem C.
A parte gráfica foi criada utilizando
a potente IDE da Embarcadero o C++ Builder.




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

#include <fmx.h>
#pragma hdrstop
#define lin  12
#define col 43
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource ("*.Windows.fmx", _PLAT_MSWINDOWS)

TForm1 *Form1;
bool x = false;
char texto [ lin ] [ col ] = {
"No Meio do Caminho",
"Carlos Drummond de Andrade",
"No meio do caminho tinha uma pedra",
"Tinha uma pedra no meio do caminho",
"Tinha uma pedra",
"No meio do caminho tinha uma pedra.",
"Nunca me esquecerei desse acontecimento",
"Na vida de minhas retinas tão fatigadas.",
"Nunca me esquecerei que no meio do caminho",
"Tinha uma pedra",
"Tinha uma pedra no meio do caminho",
"No meio do caminho tinha uma pedra." };
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
: TForm ( Owner )
{
}
int a;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
   Rectangle1 -> Width = 600;
   Rectangle1 -> Height = 300;
   Rectangle1 -> Position -> X = 0;
   Rectangle1 -> Position -> Y = 0;

   Label1 -> Position -> X = 80;
   Label1 -> Position -> Y = 20;
   Label1 -> Size -> Width = 600;
   Label1 -> Size -> Height = 250;
   Label1 -> TextSettings -> Font -> Size = 16;
   Label1 -> TextSettings -> FontColor = claBlack;
   Label1 -> Size -> PlatformDefault = False;
   Label1 -> Font -> Style = TFontStyles ( ) << fsBold;

   Text1 -> Position -> X = -45;
   Text1 -> Position -> Y = 10;
   Text1 -> Size -> Width = 700;
   Text1 -> Size -> Height = 20;
   Text1 -> TextSettings -> Font -> Size = 16;
   Text1 -> TextSettings -> FontColor = claRed;
   Text1 -> Size -> PlatformDefault = False;
   Text1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

   Text2 -> Position -> X = 77;
   Text2 -> Position -> Y = 47;
   Text2 -> Size -> Width = 700;
   Text2 -> Size -> Height = 20;
   Text2 -> TextSettings -> Font -> Size = 14;
   Text2 -> TextSettings -> FontColor = claBlack;
   Text2 -> Size -> PlatformDefault = False;
   Text2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Text2 -> Text = "Por : ";

   Text3 -> Position -> X = 165;
   Text3 -> Position -> Y = 47;
   Text3 -> Size -> Width = 700;
   Text3 -> Size -> Height = 20;
   Text3 -> TextSettings -> Font -> Size = 14;
   Text3 -> TextSettings -> FontColor = claDarkorange;
   Text3 -> Size -> PlatformDefault = False;
   Text3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Text3 -> Text = "Samuel Lima";

   Text4 -> Position -> X = 136;
   Text4 -> Position -> Y = 67;
   Text4 -> Size -> Width = 700;
   Text4 -> Size -> Height = 20;
   Text4 -> TextSettings -> Font -> Size = 14;
   Text4 -> TextSettings -> FontColor = claYellow;
   Text4 -> Size -> PlatformDefault = False;
   Text4 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Text4 -> Text = "sa_sp10@hotmail.com";

   Edit1 -> SetFocus ( );
   Edit1 -> Font -> Size = 10;
   Edit1 -> Width = 130;
   Edit1 -> Height = 17;
   Edit1 -> Position -> X = 77;
   Edit1 -> Position -> Y = 270;

   Button1 -> Width = 30;
   Button1 -> Height = 17;
   Button1 -> Position -> X = 220;
   Button1 -> Position -> Y = 270;
   Button1 -> TextSettings -> Font -> Family = "Arial";
   //Button1 -> TextSettings -> Font -> Size = 16;
   Button1 -> TextSettings -> FontColor = claBlue;

   Button2 -> Width = 40;
   Button2 -> Height = 17;
   Button2 -> Position -> X = 490;
   Button2 -> Position -> Y = 270;
   Button2 -> TextSettings -> Font -> Family = "Arial";
   Button2 -> TextSettings -> Font -> Size = 16;
   Button2 -> TextSettings -> FontColor = claRed;
   Button2 -> Text = "Sair";

   Button3 -> Width = 40;
   Button3 -> Height = 17;
   Button3 -> Position -> X = 320;
   Button3 -> Position -> Y = 270;
   Button3 -> TextSettings -> Font -> Family = "Arial";
   Button3 -> TextSettings -> Font -> Size = 16;
   Button3 -> TextSettings -> FontColor = claBlue;
   Button3 -> Text = "Por";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Sobre ( TObject* Sender ) {
   Text2 -> Visible = true;
   Text3 -> Visible = true;
   Text4 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Sobre_2 ( TObject* Sender ) {
   Text2 -> Visible = false;
   Text3 -> Visible = false;
   Text4 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Imprime_matriz ( TObject* Sender ) {
   AnsiString str_1;
   int a, b;
for ( a = 0; a < lin; a++ ) {
for ( b = 0; b < col; b++ ) {
if ( b % 43 == 0 ) {
AppendStr ( str_1, "\n" );
}
   AppendStr ( str_1, texto [ a ] [ b ] );
}
}
Label1 -> Text = str_1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {

Label_Manual ( Sender );
Imprime_matriz ( Sender );
Text1 -> Text = "FMX - APAGANDO STRING EM MATRIZ BIDIMENSIONAL";
Button2 -> Visible = true;
Edit1 -> Visible = true;
Sobre_2 ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
int g, i, j, k, lenv;
char *pt;
pt = ( char * )  malloc ( 100 );
AnsiString str_1;
String st;
st += Edit1 -> Text;
wcstombs (  pt, st.c_str ( ), 100 );
lenv = strlen ( pt );
Label1 -> Text = " ";
for ( i = 0; i < lin; i++ ) {
  for ( j = 0; j < col; j++ ) {
  if ( j % 43 == 0 ) {
  AppendStr ( str_1, "\n" );
}
                   k = 0;
   while ( texto [ i ] [ j + k ] == pt [ k ] && pt [ k ] != '\0'
                            && texto [ i ] [ j + k ] != '\0' )
                        k++;
   if ( pt [ k ] == '\0' ) {
for ( g = 0; g < lenv; g++ ) {
  strcpy ( &texto [ i ] [ j ], " " );
  AppendStr ( str_1, &texto [ i ] [ j ] );
j++;
x = true;
  }
   }
   else {
AppendStr ( str_1, texto [ i ] [ j ] );
   }
  }
}
Label1 -> Text = str_1;
if ( x == true ) {
  Edit1 -> Text = "";
              Edit1 -> SetFocus ( );
  x = false;
              Sobre_2 ( Sender );
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click ( TObject *Sender ) {
Close ( );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click ( TObject *Sender ) {
Sobre ( Sender );
}
//---------------------------------------------------------------------------

domingo, 9 de agosto de 2020

FMX - pesquisando substring em frases

  •  O C++ builder possui funções nativa para pesquisa em string,
  • Mas vamos ignorar isto e vamos usar a função,
  • strstr da biblioteca padrão string.h do C.


  • //---------------------------------------------------------------------------

  • #include <fmx.h>
  • #pragma hdrstop

  • #include "Unit1.h"
  • //---------------------------------------------------------------------------
  • #pragma package(smart_init)
  • #pragma resource "*.fmx"
  • #pragma resource ("*.Windows.fmx", _PLAT_MSWINDOWS)

  • TForm1 *Form1;

  • //---------------------------------------------------------------------------
  • __fastcall TForm1::TForm1 ( TComponent* Owner )
  • : TForm ( Owner )
  • {
  • }
  • int a;
  • bool y = false;
  • //---------------------------------------------------------------------------
  • void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
  • Rectangle1 -> Width = 600;
  • Rectangle1 -> Height = 300;
  • Rectangle1 -> Position -> X = 0;
  • Rectangle1 -> Position -> Y = 0;

  • Label1 -> Position -> X = 170;
  • Label1 -> Position -> Y = 210;
  • Label1 -> Size -> Width = 200;
  • Label1 -> Size -> Height = 30;
  • Label1 -> TextSettings -> Font -> Size = 18;
  • Label1 -> TextSettings -> FontColor = claBlue;
  • Label1 -> TextSettings -> Font -> Family = "Consolas";
  • Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
  • Label1 -> Text = "Por: Samuel Lima";

  • Label2 -> Position -> X = 170;
  • Label2 -> Position -> Y = 225;
  • Label2 -> Size -> Width = 200;
  • Label2 -> Size -> Height = 30;
  • Label2 -> TextSettings -> Font -> Size = 18;
  • Label2 -> TextSettings -> FontColor = claBlack;
  • Label2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
  • Label2 -> Text = "sa_sp10@hotmail.com";

  • Label3 -> Position -> X = 160;
  • Label3 -> Position -> Y = 145;
  • Label3 -> Size -> Width = 400;
  • Label3 -> Size -> Height = 30;
  • Label3 -> TextSettings -> Font -> Size = 18;
  • Label3 -> TextSettings -> FontColor = claRed;
  • Label3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

  • Text1 -> Position -> X = -55;
  • Text1 -> Position -> Y = 17;
  • Text1 -> Size -> Width = 700;
  • Text1 -> Size -> Height = 20;
  • Text1 -> TextSettings -> Font -> Size = 16;
  • Text1 -> TextSettings -> FontColor = claRed;
  • //Text1 -> AutoSize = True;
  • Text1 -> Size -> PlatformDefault = False;
  • Text1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
  • //Text1 -> Text = str_3;

  • Text2 -> Position -> X = -146;
  • Text2 -> Position -> Y = 47;
  • Text2 -> Size -> Width = 700;
  • Text2 -> Size -> Height = 20;
  • Text2 -> TextSettings -> Font -> Size = 14;
  • Text2 -> TextSettings -> FontColor = claBlack;
  • //Text1 -> AutoSize = True;
  • Text2 -> Size -> PlatformDefault = False;
  • Text2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

  • Text3 -> Position -> X = -132;
  • Text3 -> Position -> Y = 67;
  • Text3 -> Size -> Width = 700;
  • Text3 -> Size -> Height = 20;
  • Text3 -> TextSettings -> Font -> Size = 14;
  • Text3 -> TextSettings -> FontColor = claBlack;
  • //Text1 -> AutoSize = True;
  • Text3 -> Size -> PlatformDefault = False;
  • Text3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

  • Text4 -> Position -> X = -142;
  • Text4 -> Position -> Y = 87;
  • Text4 -> Size -> Width = 700;
  • Text4 -> Size -> Height = 20;
  • Text4 -> TextSettings -> Font -> Size = 14;
  • Text4 -> TextSettings -> FontColor = claBlack;
  • //Text4 -> AutoSize = True;
  • Text4 -> Size -> PlatformDefault = False;
  • Text4 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

  • Text5 -> Position -> X = -205;
  • Text5 -> Position -> Y = 107;
  • Text5 -> Size -> Width = 700;
  • Text5 -> Size -> Height = 20;
  • Text5 -> TextSettings -> Font -> Size = 14;
  • Text5 -> TextSettings -> FontColor = claRed;
  • //Text5 -> AutoSize = True;
  • Text5 -> Size -> PlatformDefault = False;
  • Text5 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

  • Text6 -> Position -> X = -95;
  • Text6 -> Position -> Y = 127;
  • Text6 -> Size -> Width = 700;
  • Text6 -> Size -> Height = 20;
  • Text6 -> TextSettings -> Font -> Size = 14;
  • Text6 -> TextSettings -> FontColor = claBlack;
  • //Text6 -> AutoSize = True;
  • Text6 -> Size -> PlatformDefault = False;
  • Text6 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

  • Edit1 -> SetFocus ( );
  • Edit1 -> Font -> Size = 10;
  • Edit1 -> Width = 130;
  • Edit1 -> Height = 17;
  • Edit1 -> Position -> X = 290;
  • Edit1 -> Position -> Y = 47;

  • Edit2 -> Font -> Size = 10;
  • Edit2 -> Width = 130;
  • Edit2 -> Height = 17;
  • Edit2 -> Position -> X = 290;
  • Edit2 -> Position -> Y = 67;

  • Button1 -> Width = 30;
  • Button1 -> Height = 17;
  • Button1 -> Position -> X = 390;
  • Button1 -> Position -> Y = 87;
  • Button1 -> TextSettings -> Font -> Family = "Arial";
  • //Button1 -> TextSettings -> Font -> Size = 16;
  • Button1 -> TextSettings -> FontColor = claBlue;

  • Button2 -> Width = 50;
  • Button2 -> Height = 17;
  • Button2 -> Position -> X = 470;
  • Button2 -> Position -> Y = 260;
  • Button2 -> TextSettings -> Font -> Family = "Arial";
  • Button2 -> TextSettings -> Font -> Size = 16;
  • Button2 -> TextSettings -> FontColor = claRed;
  • Button2 -> Text = "Sair";
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TForm1::FormShow ( TObject *Sender ) {
  • Label_Manual ( Sender );
  • Text1 -> Text = "FMX - PESQUISANDO SUBSTRING EM FRASES";
  • a = 0;
  • if ( a == 0 ) {
  • Text2 -> Text = "Digite uma frase : ";
  • Text3 -> Text = "Digite uma sub-frase : ";
  • Text4 -> Text = "Pesquisar na frase: ";
  • }
  • Button1 -> Text = "Ok";
  • Button2 -> Visible = false;
  • Label1 -> Visible = false;
  • Label2 -> Visible = false;
  • Edit1 -> Visible = true;
  • Edit2 -> Visible = true;
  • }
  • //---------------------------------------------------------------------------
  • void __fastcall TForm1::Button1Click ( TObject *Sender ) {
  • char str [ 50 ] = " ";
  • char str_2 [ 50 ] = " ";

  • String st;
  • st += Edit1 -> Text;
  • wcstombs (  str, st.c_str ( ), 50 );

  • String st_2;
  • st_2 += Edit2 -> Text;
  • wcstombs (  str_2, st_2.c_str ( ), 50 );

  • if (  Edit1 -> Text != "" && Edit2 -> Text != "" ) {
  •     a++;
  • if ( a == 1 ) {
  • Edit1 -> Visible = false;
  • Edit2 -> Visible = false;
  • Text3 -> Text = " ";
  • Text4 -> Text = " ";
  • Text2 -> Text = "Abaixo a frase digitada: ";

  •         Text3 -> Size -> Width = 860;
  • Text3 -> TextSettings -> FontColor = claRed;
  • Text3 -> Position -> X = -192;
  • Text3 -> Text = st;
  • }
  • char *ptr;
  • if ( strstr ( str, str_2 ) != NULL ) {
  • Text2 -> Text = " ";
  • Text3 -> Text = " ";
  • Text2 -> Text = "Abaixo a frase digitada: ";
  • Text3 -> TextSettings -> FontColor = claRed;
  • Text3 -> Position -> X = -192;
  • Text3 -> Text = st;

  • Text4 -> Position -> X = -132;
  • Text4 -> Text = "A frase contém a substring";
  • Text5 -> Text += str_2;
  •         Button1 -> Width = 100;
  • Button1 -> Position -> X = 70;
  • Button1 -> Position -> Y = 260;
  • Button1 -> Text = "Nova frase";
  • Button2 -> Visible = true;
  • Label1 -> Visible = true;
  • Label2 -> Visible = true;
  • Edit1 -> Visible = false;
  • Edit2 -> Visible = false;
  • }
  • else {
  • Text2 -> Text = " ";
  • Text3 -> Text = " ";
  • Text2 -> Text = "Abaixo a frase digitada: ";
  • Text3 -> TextSettings -> FontColor = claRed;
  • Text3 -> Position -> X = -203;
  • Text3 -> Text = st;

  • Text4 -> Position -> X = -122;
  • Text4 -> Text = "A frase não contém a substring";
  • Text5 -> Text += str_2;
  • Text6 -> Position -> Y = 177;
  • Text6 -> Text = "Tente começar tudo de novo";

  •         Button1 -> Width = 100;
  • Button1 -> Position -> X = 70;
  • Button1 -> Position -> Y = 260;
  • Button1 -> Text = "Nova frase";
  • Button2 -> Visible = true;
  • Label1 -> Visible = true;
  • Label2 -> Visible = true;
  • Edit1 -> Visible = false;
  • Edit2 -> Visible = false;

  • }
  • if ( a == 2 ) {
  • Text4 -> Text = " ";
  • Text5 -> Text = " ";
  • Text6 -> Text = " ";
  • Edit1 -> Text = "";
  • Edit2 -> Text = "";
  • Label3 -> Text = " ";
  • FormShow ( Sender );
  •   }


  • String Usuario_1 = "Corinthians";
  • String Usuario_2 = Edit2 -> Text;
  • Boolean Result_1 = SameText ( Usuario_1, Usuario_2 );
  • if ( Result_1 == True ) {
  • Beep ( 400, 500 );
  •     Label3 -> Text = "Não digite palavrões, por favor!";
  • }


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


terça-feira, 4 de agosto de 2020

FMX - separando dígitos numa frase

O Componente TEdit do FMX, possui diversas propriedades,
e uma das mais importantes é a filtre char,
podemos fazer filtragem de qualquer caractere,
ou de dígitos, só passa o que queremos que passe,
por esta entrada de dados, mas deixando isto de lado,
resolvemos criar uma rotina de códigos para fazer
a separação de dígitos contidos numa frase,
a parte lógica foi criada em C, mas pode ser convertido
para qualquer linguagem, não se assustem com os muitos códigos
da interface gráfica, boa sorte, bons estudos, e até o próximo post.


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

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource ("*.Windows.fmx", _PLAT_MSWINDOWS)

TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
: TForm ( Owner )
{
}
int a, x;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 600;
Rectangle1 -> Height = 300;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;

Label1 -> Position -> X = 170;
Label1 -> Position -> Y = 210;
Label1 -> Size -> Width = 200;
Label1 -> Size -> Height = 30;
Label1 -> TextSettings -> Font -> Size = 18;
Label1 -> TextSettings -> FontColor = claBlack;
Label1 -> TextSettings -> Font -> Family = "Consolas";
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label1 -> Text = "Por: Samuel Lima";

Label2 -> Position -> X = 170;
Label2 -> Position -> Y = 225;
Label2 -> Size -> Width = 200;
Label2 -> Size -> Height = 30;
Label2 -> TextSettings -> Font -> Size = 18;
Label2 -> TextSettings -> FontColor = claBlack;
Label2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label2 -> Text = "sa_sp10@hotmail.com";

Text1 -> Position -> X = -55;
Text1 -> Position -> Y = 17;
Text1 -> Size -> Width = 700;
Text1 -> Size -> Height = 20;
Text1 -> TextSettings -> Font -> Size = 16;
Text1 -> TextSettings -> FontColor = claRed;
//Text1 -> AutoSize = True;
Text1 -> Size -> PlatformDefault = False;
Text1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text1 -> Text = str_3;

Text2 -> Position -> X = -145;
Text2 -> Position -> Y = 47;
Text2 -> Size -> Width = 700;
Text2 -> Size -> Height = 20;
Text2 -> TextSettings -> Font -> Size = 14;
Text2 -> TextSettings -> FontColor = claBlack;
//Text1 -> AutoSize = True;
Text2 -> Size -> PlatformDefault = False;
Text2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

Text3 -> Position -> X = -156;
Text3 -> Position -> Y = 67;
Text3 -> Size -> Width = 700;
Text3 -> Size -> Height = 20;
Text3 -> TextSettings -> Font -> Size = 14;
Text3 -> TextSettings -> FontColor = claRed;
//Text1 -> AutoSize = True;
Text3 -> Size -> PlatformDefault = False;
Text3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

Text4 -> Position -> X = -76;
Text4 -> Position -> Y = 87;
Text4 -> Size -> Width = 700;
Text4 -> Size -> Height = 20;
Text4 -> TextSettings -> Font -> Size = 14;
Text4 -> TextSettings -> FontColor = claBlack;
//Text4 -> AutoSize = True;
Text4 -> Size -> PlatformDefault = False;
Text4 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text4 -> Text = "Por : ";

Text5 -> Position -> X = -166;
Text5 -> Position -> Y = 107;
Text5 -> Size -> Width = 700;
Text5 -> Size -> Height = 20;
Text5 -> TextSettings -> Font -> Size = 14;
Text5 -> TextSettings -> FontColor = claRed;
//Text5 -> AutoSize = True;
Text5 -> Size -> PlatformDefault = False;
Text5 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text5 -> Text = "Samuel lima";

Text6 -> Position -> X = -95;
Text6 -> Position -> Y = 127;
Text6 -> Size -> Width = 700;
Text6 -> Size -> Height = 20;
Text6 -> TextSettings -> Font -> Size = 14;
Text6 -> TextSettings -> FontColor = claBlack;
//Text6 -> AutoSize = True;
Text6 -> Size -> PlatformDefault = False;
Text6 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text6 -> Text = "sa_sp10@hotmail.com";

Text7 -> Position -> X = -176;
Text7 -> Position -> Y = 147;
Text7 -> Size -> Width = 700;
Text7 -> Size -> Height = 20;
Text7 -> TextSettings -> Font -> Size = 14;
Text7 -> TextSettings -> FontColor = claRed;
//Text6 -> AutoSize = True;
Text7 -> Size -> PlatformDefault = False;
Text7 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text6 -> Text = "sa_sp10@hotmail.com";

Edit1 -> SetFocus ( );
Edit1 -> Font -> Size = 10;
Edit1 -> Width = 130;
Edit1 -> Height = 17;
Edit1 -> Position -> X = 277;
Edit1 -> Position -> Y = 47;

Button1 -> Width = 30;
Button1 -> Height = 17;
Button1 -> Position -> X = 415;
Button1 -> Position -> Y = 47;
Button1 -> TextSettings -> Font -> Family = "Arial";
//Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claBlue;

Button2 -> Width = 50;
Button2 -> Height = 17;
Button2 -> Position -> X = 470;
Button2 -> Position -> Y = 260;
Button2 -> TextSettings -> Font -> Family = "Arial";
Button2 -> TextSettings -> Font -> Size = 16;
Button2 -> TextSettings -> FontColor = claRed;
Button2 -> Text = "Sair";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
Label_Manual ( Sender );
Text1 -> Text = "C++ BUILDER - SEPARANDO DÍGITOS EM FRASES";
a = 0;
if ( a == 0 )
Text2 -> Text = "Digite uma frase : ";
Button1 -> Text = "Ok";
Button2 -> Visible = false;
Label1 -> Visible = false;
Label2 -> Visible = false;
Edit1 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
a++;
int i, j, k, h = 0, lenv, lenv_1;
char Num [ ] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
lenv_1 = strlen ( Num );

char str [ 50 ] = " ";
char Vet [ 50 ];
String st;
st += Edit1 -> Text;
wcstombs (  str, st.c_str ( ), 50 );
lenv = strlen ( str );

if ( a == 1 ) {
Edit1 -> Visible = false;
Text2 -> Text = "Abaixo a frase digitada: ";
Button1 -> Width = 100;
Button1 -> Height = 17;
Button1 -> Position -> X = 130;
Button1 -> Position -> Y = 260;
Button1 -> TextSettings -> Font -> Family = "Arial";
Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claRed;
Button1 -> Text = "Pressione";
for ( i = 0; i < lenv; i++ ) {
Text3 -> Text += str [ i ];
}
}
if ( a == 2 ) {
Text4 -> Text = "Imprimindo abaixo só os caracteres da frase";
for ( i = 0; i < lenv; i++ ) {
for ( j = 0; j < lenv; j++ )
if ( str [ i ] == Num [ j ] )
break;
if ( j == lenv ) {
Text5 -> Text += str [ i ];
}
}
}

if ( a == 3 ) {
Text6 -> Text = "Imprimindo abaixo só os dígitos da frase";
for ( i = 0; i < lenv; i++ ) {
for ( j = 0; j < lenv_1; j++ ) {
if ( Num [ j ] == str [ i ] ) {
Vet [ h ] = str [ i ];
h++;
}
}
}
k = h;
for ( h = 0; h < k; h++ ) {
Text7 -> Text += Vet [ h ];
}
Button1 -> Text = "Nova frase";
Button2 -> Visible = true;
Label1 -> Visible = true;
Label2 -> Visible = true;
}
if ( a == 4 ) {
Text3 -> Text = " ";
Text4 -> Text = " ";
Text5 -> Text = " ";
Text6 -> Text = " ";
Text7 -> Text = " ";
Edit1 -> Text = "";
FormShow ( Sender );
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click ( TObject *Sender ) {
Close ( );
}
//---------------------------------------------------------------------------


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Objects.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Edit.hpp>
#include <FMX.Graphics.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRectangle *Rectangle1;
TLabel *Label1;
TLabel *Label2;

TEdit *Edit1;

TButton *Button1;
TButton *Button2;

TText *Text1;
TText *Text2;
TText *Text3;
TText *Text4;
TText *Text5;
TText *Text6;
TText *Text7;

void __fastcall FormShow ( TObject *Sender );
void __fastcall Label_Manual ( 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


segunda-feira, 3 de agosto de 2020

FMX - separando vogais e consoantes

O Componente TEdit do FMX, possui diversas propriedades,
e uma das mais importantes é a filtre char,
podemos fazer filtragem de qualquer caractere,
ou de dígitos, só passa o que queremos que passe,
por esta entrada de dados, mas deixando isto de lado,
resolvemos criar uma rotina de códigos para fazer
a separação de vogais e de consoantes de uma frase,
a parte lógica foi criada em C, mas pode ser convertido
para qualquer linguagem, não se assustem com os muitos códigos
da interface gráfica, boa sorte, bons estudos, e até o próximo post.


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

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource ("*.Windows.fmx", _PLAT_MSWINDOWS)

TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
: TForm ( Owner )
{
}
int a, x;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 600;
Rectangle1 -> Height = 300;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;

Label1 -> Position -> X = 170;
Label1 -> Position -> Y = 210;
Label1 -> Size -> Width = 200;
Label1 -> Size -> Height = 30;
Label1 -> TextSettings -> Font -> Size = 18;
Label1 -> TextSettings -> FontColor = claBlack;
Label1 -> TextSettings -> Font -> Family = "Consolas";
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label1 -> Text = "Por: Samuel Lima";

Label2 -> Position -> X = 170;
Label2 -> Position -> Y = 225;
Label2 -> Size -> Width = 200;
Label2 -> Size -> Height = 30;
Label2 -> TextSettings -> Font -> Size = 18;
Label2 -> TextSettings -> FontColor = claBlack;
Label2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label2 -> Text = "sa_sp10@hotmail.com";

Text1 -> Position -> X = -55;
Text1 -> Position -> Y = 17;
Text1 -> Size -> Width = 700;
Text1 -> Size -> Height = 20;
Text1 -> TextSettings -> Font -> Size = 16;
Text1 -> TextSettings -> FontColor = claRed;
//Text1 -> AutoSize = True;
Text1 -> Size -> PlatformDefault = False;
Text1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text1 -> Text = str_3;

Text2 -> Position -> X = -145;
Text2 -> Position -> Y = 47;
Text2 -> Size -> Width = 700;
Text2 -> Size -> Height = 20;
Text2 -> TextSettings -> Font -> Size = 14;
Text2 -> TextSettings -> FontColor = claBlack;
//Text1 -> AutoSize = True;
Text2 -> Size -> PlatformDefault = False;
Text2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

Text3 -> Position -> X = -186;
Text3 -> Position -> Y = 67;
Text3 -> Size -> Width = 700;
Text3 -> Size -> Height = 20;
Text3 -> TextSettings -> Font -> Size = 14;
Text3 -> TextSettings -> FontColor = claRed;
//Text1 -> AutoSize = True;
Text3 -> Size -> PlatformDefault = False;
Text3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

Text4 -> Position -> X = -76;
Text4 -> Position -> Y = 87;
Text4 -> Size -> Width = 700;
Text4 -> Size -> Height = 20;
Text4 -> TextSettings -> Font -> Size = 14;
Text4 -> TextSettings -> FontColor = claBlack;
//Text4 -> AutoSize = True;
Text4 -> Size -> PlatformDefault = False;
Text4 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text4 -> Text = "Por : ";

Text5 -> Position -> X = -205;
Text5 -> Position -> Y = 107;
Text5 -> Size -> Width = 700;
Text5 -> Size -> Height = 20;
Text5 -> TextSettings -> Font -> Size = 14;
Text5 -> TextSettings -> FontColor = claRed;
//Text5 -> AutoSize = True;
Text5 -> Size -> PlatformDefault = False;
Text5 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text5 -> Text = "Samuel lima";

Text6 -> Position -> X = -95;
Text6 -> Position -> Y = 127;
Text6 -> Size -> Width = 700;
Text6 -> Size -> Height = 20;
Text6 -> TextSettings -> Font -> Size = 14;
Text6 -> TextSettings -> FontColor = claBlack;
//Text6 -> AutoSize = True;
Text6 -> Size -> PlatformDefault = False;
Text6 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text6 -> Text = "sa_sp10@hotmail.com";

Text7 -> Position -> X = -212;
Text7 -> Position -> Y = 147;
Text7 -> Size -> Width = 700;
Text7 -> Size -> Height = 20;
Text7 -> TextSettings -> Font -> Size = 14;
Text7 -> TextSettings -> FontColor = claRed;
//Text6 -> AutoSize = True;
Text7 -> Size -> PlatformDefault = False;
Text7 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text6 -> Text = "sa_sp10@hotmail.com";

Edit1 -> SetFocus ( );
Edit1 -> Font -> Size = 10;
Edit1 -> Width = 130;
Edit1 -> Height = 17;
Edit1 -> Position -> X = 277;
Edit1 -> Position -> Y = 47;

Button1 -> Width = 30;
Button1 -> Height = 17;
Button1 -> Position -> X = 415;
Button1 -> Position -> Y = 47;
Button1 -> TextSettings -> Font -> Family = "Arial";
//Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claBlue;

Button2 -> Width = 50;
Button2 -> Height = 17;
Button2 -> Position -> X = 470;
Button2 -> Position -> Y = 260;
Button2 -> TextSettings -> Font -> Family = "Arial";
Button2 -> TextSettings -> Font -> Size = 16;
Button2 -> TextSettings -> FontColor = claRed;
Button2 -> Text = "Sair";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
Label_Manual ( Sender );
Text1 -> Text = "FMX - SEPARANDO VOGAIS E CONSOANTES EM FRASES";
a = 0;
if ( a == 0 )
Text2 -> Text = "Digite uma frase : ";
Button1 -> Text = "Ok";
Button2 -> Visible = false;
Label1 -> Visible = false;
Label2 -> Visible = false;
Edit1 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
a++;
int i, j, k, h = 0, lenv, lenv_1;
char Vogais [ ] = { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
lenv_1 = strlen ( Vogais );

char str [ 50 ] = " ";
char Vet [ 50 ];
String st;
st += Edit1 -> Text;
wcstombs (  str, st.c_str ( ), 50 );
lenv = strlen ( str );

if ( a == 1 ) {
Edit1 -> Visible = false;
Text2 -> Text = "Abaixo a frase digitada: ";
Button1 -> Width = 100;
Button1 -> Height = 17;
Button1 -> Position -> X = 130;
Button1 -> Position -> Y = 260;
Button1 -> TextSettings -> Font -> Family = "Arial";
Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claRed;
Button1 -> Text = "Pressione";
for ( i = 0; i < lenv; i++ ) {
Text3 -> Text += str [ i ];
}
}
if ( a == 2 ) {
Text4 -> Text = "Imprimindo abaixo só as consoantes da frase";
for ( i = 0; i < lenv; i++ ) {
for ( j = 0; j < lenv; j++ )
if ( str [ i ] == Vogais [ j ] )
break;
if ( j == lenv ) {
Text5 -> Text += str [ i ];
}
}
}

if ( a == 3 ) {
Text6 -> Text = "Imprimindo abaixo só as vogais da frase";
for ( i = 0; i < lenv; i++ ) {
for ( j = 0; j < lenv_1; j++ ) {
if ( Vogais [ j ] == str [ i ] ) {
Vet [ h ] = str [ i ];
h++;
}
}
}
k = h;
for ( h = 0; h < k; h++ ) {
Text7 -> Text += Vet [ h ];
}
Button1 -> Text = "Nova frase";
Button2 -> Visible = true;
Label1 -> Visible = true;
Label2 -> Visible = true;
}
if ( a == 4 ) {
Text3 -> Text = " ";
Text4 -> Text = " ";
Text5 -> Text = " ";
Text6 -> Text = " ";
Text7 -> Text = " ";
Edit1 -> Text = "";
FormShow ( Sender );
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click ( TObject *Sender ) {
Close ( );
}
//---------------------------------------------------------------------------


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Objects.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Edit.hpp>
#include <FMX.Graphics.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRectangle *Rectangle1;
TLabel *Label1;
TLabel *Label2;

TEdit *Edit1;

TButton *Button1;
TButton *Button2;

TText *Text1;
TText *Text2;
TText *Text3;
TText *Text4;
TText *Text5;
TText *Text6;
TText *Text7;

void __fastcall FormShow ( TObject *Sender );
void __fastcall Label_Manual ( 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