sábado, 25 de julho de 2020

FMX - marcando as ocorrências de múltiplos

Se criamos um programa semelhante a este no Qt,
e mostramos seu funcionamento para todos os que
se interessam por programação em desktop,
o que poderia nos impedir de criar também uma versão
no C++ builder da Embarcadero?
nós somos fanáticos por C++ e isto faz a diferença. 
Este programa marca todas as ocorrências 
dos múltiplos de um número dentro de uma matriz
de inteiros de dez mil elementos.



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

#include <fmx.h>
#pragma hdrstop

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

TForm1 *Form1;
//AnsiString str_1;
//AnsiString str_2;
AnsiString str_3 = "C++ BUILDER - MARCANDO AS OCORRÊNCIAS DE MÚLTIPLOS";
int n;
int a = 0, b = 0;
int A [ 100 ] [ 100 ], i;
bool x = false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner )
: TForm ( Owner )
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Imprime_matriz ( TObject* Sender ) {
    AnsiString str_1;
//AnsiString str_2;
  for( i = 0; i < 10000; i++ ) {
A [ b ] [ a ] =  i;
a++;
}
for ( a = 0; a < 100; a++ ) {
for ( b = 0; b < 100; b++ ) {

AppendStr ( str_1, "\t" );

if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_1, "\n" );
}

if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 ) {
AppendStr ( str_1, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 ) {
AppendStr ( str_1, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 ) {
AppendStr ( str_1, "0" );
}
   AppendStr ( str_1, A [ a ] [ b ] );

}
}
Label1 -> Text = str_1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
   Rectangle1 -> Width = 750;
   Rectangle1 -> Height = 400;
   Rectangle1 -> Position -> X = 0;
   Rectangle1 -> Position -> Y = 0;

   Edit1 -> SetFocus ( );
   Edit1 -> Font -> Size = 10;
   Edit1 -> Width = 70;
   Edit1 -> Height = 20;
   Edit1 -> Position -> X = 80;
   Edit1 -> Position -> Y = 353;

   Button1 -> Visible = true;
   Button1 -> Width = 30;
   Button1 -> Height = 20;
   Button1 -> Position -> X = 165;
   Button1 -> Position -> Y = 353;
   Button1 -> TextSettings -> Font -> Family = "Arial";
   //Button1 -> TextSettings -> Font -> Size = 16;
   Button1 -> TextSettings -> FontColor = claBlue;

   Label1 -> Position -> X = 40;
   Label1 -> Position -> Y = -30;
   Label1 -> Size -> Width = 650;
   Label1 -> Size -> Height = 16720;
   Label1 -> TextSettings -> Font -> Size = 16;
   Label1 -> TextSettings -> FontColor = claBlack;
   Label1 -> Font -> Style = TFontStyles ( ) << fsBold;

   Label2 -> Position -> X = 40;
   Label2 -> Position -> Y = -30;
   Label2 -> Size -> Width = 650;
   Label2 -> Size -> Height = 16720;
   Label2 -> TextSettings -> Font -> Size = 16;
   Label2 -> TextSettings -> FontColor = claRed;
   Label2 -> Font -> Style = TFontStyles ( ) << fsBold;

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

   Text2 -> Position -> X = -210;
   Text2 -> Position -> Y = 330;
   Text2 -> Size -> Width = 700;
   Text2 -> Size -> Height = 20;
   Text2 -> TextSettings -> Font -> Size = 12;
   Text2 -> TextSettings -> FontColor = claBlack;
   //Text2 -> AutoSize = True;
   Text2 -> Size -> PlatformDefault = False;
   //Text2 -> Font -> Style = TFontStyles ( ) << fsBold;
   Text2 -> Text = "Digite um número: ";

   Text3 -> Position -> X = 30;
   Text3 -> Position -> Y = 320;
   Text3 -> Size -> Width = 700;
   Text3 -> Size -> Height = 20;
   Text3 -> TextSettings -> Font -> Size = 18;
   Text3 -> TextSettings -> FontColor = claBlack;
   //Text3 -> AutoSize = True;
   Text3 -> Size -> PlatformDefault = False;
   Text3 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

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

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

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

   Form1 -> Left = 426;
   Form1 -> Top = 85;
   Form1 -> Caption = "C++ BUILDER - MÚLTIPLOS EM MATRIZ DE INTEIROS";
   Form1 -> ClientHeight = 400;
   Form1 -> ClientWidth = 750;

   ScrollBox1 -> Width = 720;
   ScrollBox1 -> Height = 250;
   ScrollBox1 -> Position -> X = 20;
   ScrollBox1 -> Position -> Y = 68;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
Label_Manual ( Sender );
Imprime_matriz ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click ( TObject *Sender ) {
   int totMult;
   AnsiString str_1;
   AnsiString str_2;
   String str_4;
    Beep ( 500, 500 );
n = StrToInt ( Edit1 -> Text );
str_2 = " ";
/*
for ( a = 0; a < 100; a++ ) {
for ( b = 0; b < 100; b++ ) {
AppendStr ( str_2, "\t" );
if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_2, "\n" );
}
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 && ( A [ a ] [ b ] % n == 0 ) ) {
AppendStr ( str_2, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 && ( A [ a ] [ b ] % n == 0 ) ) {
AppendStr ( str_2, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 && ( A [ a ] [ b ] % n == 0 ) ) {
AppendStr ( str_2, "0" );
}
if ( A [ a ] [ b ] % n == 0 ) {
++totMult;
AppendStr ( str_2, A [ a ] [ b ] );
str_4 = totMult - 2;
   }
}
}

//Label2 -> Text = str_2;

Text3 -> Text = " ";
Text3 -> Text = Text3 -> Text + "Encontrado ";
Text3 -> Text = Text3 -> Text + str_4;
Text3 -> Text = Text3 -> Text + " múltiplos de ";
Text3 -> Text = Text3 -> Text + n;
//Text3 -> Text = Text3 -> Text + " na matriz";
*/
Label1 -> Text = " ";
for ( a = 0; a < 100; a++ ) {
for ( b = 0; b < 100; b++ ) {
AppendStr ( str_1, "\t" );
AppendStr ( str_2, "\t" );
if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_1, "\n" );
AppendStr ( str_2, "\n" );
}
//==================================================================
if ( A [ a ] [ b ] % n == 0 ) {
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 ) {
AppendStr ( str_1, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 ) {
AppendStr ( str_1, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 ) {
AppendStr ( str_1, "0" );
}
str_1 += A [ a ] [ b ];
   }
   else {
   if ( A [ a ] [ b ] % 10 == 0 ) {
AppendStr ( str_2, "\n" );
}
if ( A [ a ] [ b ] >= 0 && A [ a ] [ b ] < 10 ) {
AppendStr ( str_2, "000" );
}
if ( A [ a ] [ b ] >= 10 && A [ a ] [ b ] < 100 ) {
AppendStr ( str_2, "00" );
}
if ( A [ a ] [ b ] >= 100 && A [ a ] [ b ] < 1000 ) {
AppendStr ( str_2, "0" );
}
str_2 += A [ a ] [ b ];
   }
   //==================================================================
}
}

Label1 -> Text = str_2;
//Label2 -> Text = str_1;

Edit1 -> Text = "";
Edit1 -> SetFocus ( );
}

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


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.Layouts.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Objects.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRectangle *Rectangle1;
TEdit *Edit1;
TButton *Button1;
TScrollBox *ScrollBox1;

TLabel *Label1;
TLabel *Label2;

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

void __fastcall FormShow ( TObject *Sender );
void __fastcall Label_Manual ( TObject *Sender );
void __fastcall Button1Click (TObject *Sender );
void __fastcall Imprime_matriz ( TObject* Sender );

private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif



object Form1: TForm1
  Left = 426
  Top = 85
  Caption = 'Form1'
  ClientHeight = 350
  ClientWidth = 789
  Fill.Kind = Gradient
  Fill.Gradient.Points = <
    item
      Color = xFF00FF1A
      Offset = 0.000000000000000000
    end
    item
      Color = claWhite
      Offset = 1.000000000000000000
    end>
  Fill.Gradient.StartPosition.X = 0.500000000000000000
  Fill.Gradient.StartPosition.Y = 1.000000000000000000
  Fill.Gradient.StopPosition.X = 0.499999970197677600
  Fill.Gradient.StopPosition.Y = 0.000000000000000000
  Position = Designed
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  OnShow = FormShow
  Left = 426
  Top = 85
  DesignerMasterStyle = 0
  object Text1: TText
    Position.X = 536.000000000000000000
    Position.Y = 8.000000000000000000
    TextSettings.Font.Family = 'Consolas'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000100000004000000}
    TextSettings.FontColor = claCrimson
  end
  object Text2: TText
    Position.X = 536.000000000000000000
    Position.Y = 64.000000000000000000
    TextSettings.Font.Family = 'Consolas'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000100000004000000}
    TextSettings.FontColor = claCrimson
  end
  object Rectangle1: TRectangle
    Position.X = 704.000000000000000000
    Position.Y = 64.000000000000000000
    Size.Width = 81.000000000000000000
    Size.Height = 73.000000000000000000
    Size.PlatformDefault = False
    Stroke.Color = claBlue
    Stroke.Thickness = 10.000000000000000000
    object ScrollBox1: TScrollBox
      Position.X = 16.000000000000000000
      Position.Y = -193.000000000000000000
      Size.Width = 49.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
      Viewport.Width = 49.000000000000000000
      Viewport.Height = 34.000000000000000000
      object Label1: TLabel
        StyledSettings = [FontColor]
        Position.X = 496.000000000000000000
        Position.Y = 17.000000000000000000
        TextSettings.Font.Family = 'alarm clock'
        TextSettings.Font.Size = 14.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TabOrder = 0
      end
      object Label2: TLabel
        StyledSettings = []
        Position.X = 496.000000000000000000
        Position.Y = 17.000000000000000000
        TextSettings.Font.Family = 'alarm clock'
        TextSettings.Font.Size = 14.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claRed
        TabOrder = 1
      end
    end
    object Edit1: TEdit
      Touch.InteractiveGestures = [LongTap, DoubleTap]
      TabOrder = 1
      Position.X = 13.000000000000000000
      Position.Y = 11.000000000000000000
      Size.Width = 52.000000000000000000
      Size.Height = 22.000000000000000000
      Size.PlatformDefault = False
    end
  end
  object Text3: TText
    Position.X = 536.000000000000000000
    Position.Y = 120.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Text4: TText
    Position.X = 536.000000000000000000
    Position.Y = 176.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Text5: TText
    Position.X = 536.000000000000000000
    Position.Y = 232.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Text6: TText
    Position.X = 536.000000000000000000
    Position.Y = 288.000000000000000000
    TextSettings.Font.Family = 'Bahnschrift'
    TextSettings.Font.Size = 14.000000000000000000
    TextSettings.Font.StyleExt = {00070000000000000003000000}
    TextSettings.FontColor = claFirebrick
  end
  object Button1: TButton
    Position.X = 712.000000000000000000
    Position.Y = 147.000000000000000000
    Size.Width = 65.000000000000000000
    Size.Height = 30.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 6
    Text = 'Ok'
    OnClick = Button1Click
  end
end

quarta-feira, 22 de julho de 2020

C++ builder - desenhando formas geométricas

Desenhar formas geométricas no C++ builder
é tarefa muito fácil, podemos arrastar e soltar
os componentes, ou criá-los na mão inserindo códigos.
Neste exemplo preferi arrastar e soltar no form,
acessando as propriedades de cada elemento,
personalizando de acordo com o que achei necessário.


Veja os códigos abaixo a maioria gerados pelo programa:

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

#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::OnPaint ( TObject *Sender ) {
Label1 -> Caption = "C++ BUILDER - DESENHANDO FORMAS GEOMÉTRICAS";
}

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

void __fastcall TForm1::SairClick(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
TButton *Sair;
TShape *Shape1;
TShape *Shape2;
TShape *Shape3;
TShape *Shape4;
TShape *Shape5;
TShape *Shape6;
TShape *Shape7;
TShape *Shape8;
TShape *Shape9;
TShape *Shape10;
TShape *Shape11;
TLabel *Label1;
void __fastcall OnPaint(TObject *Sender);
void __fastcall SairClick(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 = 607
  Height = 328
  AutoScroll = True
  Caption = 'C++ BUILDER - DESENHANDO FORMAS GEOM'#201'TRICAS'
  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 Shape1: TShape
    Left = 48
    Top = 48
    Width = 65
    Height = 65
    Brush.Color = clBlue
  end
  object Shape2: TShape
    Left = 48
    Top = 160
    Width = 65
    Height = 66
    Brush.Style = bsClear
    Pen.Color = clAqua
    Pen.Style = psDash
    Pen.Width = 5
  end
  object Shape3: TShape
    Left = 144
    Top = 80
    Width = 65
    Height = 33
    Brush.Color = clRed
  end
  object Shape4: TShape
    Left = 144
    Top = 192
    Width = 65
    Height = 33
    Pen.Color = clBlue
    Pen.Width = 5
  end
  object Shape5: TShape
    Left = 248
    Top = 48
    Width = 65
    Height = 65
    Brush.Color = clFuchsia
    Shape = stCircle
  end
  object Shape6: TShape
    Left = 248
    Top = 160
    Width = 65
    Height = 65
    Brush.Color = clGreen
    Pen.Color = clRed
    Pen.Width = 5
    Shape = stCircle
  end
  object Shape7: TShape
    Left = 368
    Top = 64
    Width = 97
    Height = 49
    Brush.Color = clLime
    Shape = stEllipse
  end
  object Shape8: TShape
    Left = 368
    Top = 176
    Width = 97
    Height = 49
    Brush.Color = clAqua
    Pen.Width = 5
    Shape = stEllipse
  end
  object Shape9: TShape
    Left = 471
    Top = 64
    Width = 97
    Height = 49
    Brush.Color = clYellow
    Shape = stRoundSquare
  end
  object Shape10: TShape
    Left = 471
    Top = 176
    Width = 97
    Height = 49
    Brush.Color = clBlack
    Pen.Color = clYellow
    Pen.Width = 5
    Shape = stRoundSquare
  end
  object Shape11: TShape
    Left = 0
    Top = 0
    Width = 590
    Height = 290
    Brush.Style = bsClear
    Pen.Width = 10
    Shape = stRoundRect
  end
  object Label1: TLabel
    Left = 32
    Top = 16
    Width = 60
    Height = 25
    Caption = 'Label1'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -21
    Font.Name = 'Tahoma'
    Font.Style = [fsItalic]
    ParentFont = False
  end
  object Sair: TButton
    Left = 264
    Top = 248
    Width = 75
    Height = 25
    Caption = 'Sair'
    TabOrder = 0
    OnClick = SairClick
  end

end

terça-feira, 21 de julho de 2020

FMX - Embaralhando frases

Este programa foi criado num projeto C++,
utilizando é claro o C++ Builder da Embarcadero,
mas a parte lógica foi criada em C,
sendo que nada impede os mais experientes
converterem este código para outras linguagens.
Fiz uso da biblioteca FMX,
que é simplesmente incrível e poderosa.
A maioria de meus programas no C++ Builder,
eu utilizo a biblioteca VCL,
mas as vezes sinto falta do FMX,
e me rendo a sua soberania.
Viva o C++, Viva o C++ Builder, Viva FMX!



Veja abaixo os códigos do programa:

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

#include <fmx.h>
#pragma hdrstop
#include <time.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
int a;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
 //---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
   Image1 -> Width = 600;
   Image1 -> Height = 350;
   Image1 -> Position -> X = 0;
   Image1 -> Position -> Y = 0;

   Image2 -> Width = 600;
   Image2 -> Height = 350;
   Image2 -> Position -> X = 0;
   Image2 -> Position -> Y = 0;

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

   Label1 -> Position -> X = 140;
   Label1 -> Position -> Y = 90;
   Label1 -> Size -> Width = 400;
   Label1 -> Size -> Height = 35;
   Label1 -> TextSettings -> Font -> Size = 19;
   Label1 -> TextSettings -> FontColor = claRed;
   Label1 -> Size -> PlatformDefault = False;
   Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

   Label2 -> Position -> X = 140;
   Label2 -> Position -> Y = 170;
   Label2 -> Size -> Width = 400;
   Label2 -> Size -> Height = 35;
   Label2 -> TextSettings -> Font -> Size = 19;
   Label2 -> TextSettings -> FontColor = claBlue;
   Label2 -> Size -> PlatformDefault = False;
   Label2 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

   Button1 -> TextSettings -> Font -> Size = 16;
   Button1 -> TextSettings -> FontColor = claBlue;
   Button1 -> TextSettings -> Font -> Family = "Arial";
   Button1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
   Button1 -> Position -> X = 430;
   Button1 -> Position -> Y = 35;
   Button1 -> Height = 18;
   Button1 -> Width = 30;
   Button1 -> Text = "OK";
   Button1 -> OnClick = FormShow;

   RoundRect1 -> Position -> X = 340;
   RoundRect1 -> Position -> Y = 270;
   RoundRect1 -> Height = 18;
   RoundRect1 -> Width = 100;
   //RoundRect1 -> Text = "NOVA FRASE";

}
//---------------------------------------------------------------------------
int Resolve_Problema ( int x ) {
int j, b, p;

int lenv;
char *Vet;
char *Vet_2;
String st;
char *r;
st += Form1 -> Edit1 -> Text;

Vet = ( char * )  malloc ( 28 );
r = Vet;

wcstombs (  Vet, st.c_str ( ), 50 );
Form1 -> Label1 -> Text = Vet;

if ( x >= 2 ) {
//Beep ( 500, 500 );
srand ( time ( NULL ) );
for ( b = 0; b < strlen ( Vet ); b++ ) {
j = rand ( ) % ( strlen ( Vet ) );
char t = r [ j ];
r [ j ] = r [ b ];
r [ b ] = t;
}
Form1 -> Label2 -> Text = " ";
for ( p = 0; p < strlen ( Vet ); p++ ) {
  Form1 -> Label2 -> Text = Form1 -> Label2 -> Text + r [ p ];
}
}
return ( 0 );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
int x;
Label_Manual ( Sender );
a++;
x++;
   Resolve_Problema ( x );
   Image2 -> Visible = false;
   Image1 -> Visible = true;
   RoundRect1 -> Visible = false;
if ( a >= 2 ) {
Form1 -> Image1 -> Visible = false;
Form1 -> Image2 -> Visible = true;
Edit1 -> Visible = false;

Button1 -> Position -> X = 140;
Button1 -> Position -> Y = 270;
Button1 -> Height = 18;
Button1 -> Width = 100;
Button1 -> Text = "EMBARALHA";
RoundRect1 -> Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect1Click ( TObject *Sender ) {
   a = 0;
   Label_Manual ( Sender );
   FormShow ( Sender );
   Image2 -> Visible = false;
   Image1 -> Visible = true;
   Edit1 -> Visible = true;
   Label1 -> Text = " ";
   Label2 -> Text = " ";
}

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



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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.Objects.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TImage *Image2;
TEdit *Edit1;
TButton *Button1;
TLabel *Label1;
TLabel *Label2;
TRoundRect *RoundRect1;
void __fastcall FormShow(TObject *Sender);
    void __fastcall Label_Manual ( TObject *Sender );
void __fastcall RoundRect1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

segunda-feira, 20 de julho de 2020

FMX - Imprimindo tabuada

Criar uma tabuada em C ou C++ é tarefa muito fácil,
qualquer iniciante pode fazer, mas esta aqui usa 
uma janela gráfica feita no C++ Builder da Embarcadero,
acompanhem seu funcionamento no vídeo abaixo:



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

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
int x;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
   Edit1 -> SetFocus ( );
   Edit1 -> Font -> Size = 10;
   Edit1 -> Width = 90;
   Edit1 -> Height = 20;
   Edit1 -> Position -> X = 180;
   Edit1 -> Position -> Y = 70;

   Image1 -> Width = 600;
   Image1 -> Height = 350;
   Image1 -> Position -> X = 0;
   Image1 -> Position -> Y = 0;

   Image2 -> Width = 600;
   Image2 -> Height = 350;
   Image2 -> Position -> X = 0;
   Image2 -> Position -> Y = 0;

   Label1 -> Position -> X = 230;
   Label1 -> Position -> Y = -10;
   Label1 -> Size -> Width = 380;
   Label1 -> Size -> Height = 375;
   Label1 -> TextSettings -> Font -> Size = 14;
   Label1 -> TextSettings -> FontColor = claBlack;
   Label1 -> Size -> PlatformDefault = False;
   Label1 -> Font -> Style = TFontStyles ( ) << fsBold;

   RoundRect1 -> Width = 85;
   RoundRect1 -> Height = 25;
   RoundRect1 -> Position -> X = 290;
   RoundRect1 -> Position -> Y = 67;

   RoundRect2 -> Width = 85;
   RoundRect2 -> Height = 25;
   RoundRect2 -> Position -> X = 290;
   RoundRect2 -> Position -> Y = 67;
   RoundRect2 -> OnClick = FormShow;

   RoundRect3 -> Width = 119;
   RoundRect3 -> Height = 25;
   RoundRect3 -> Position -> X = 206;
   RoundRect3 -> Position -> Y = 270;

   RoundRect4 -> Width = 119;
   RoundRect4 -> Height = 25;
   RoundRect4 -> Position -> X = 206;
   RoundRect4 -> Position -> Y = 270;
}
//---------------------------------------------------------------------------
int verificaTabuada ( int n ) {
int i, b;
for ( i = 1; i <= 10; i++ ) {
b = n * i;
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + StrToInt ( n );
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + " X ";
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + StrToInt ( i );
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + " = ";
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + StrToInt ( b );
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + "\n";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
   Label_Manual ( Sender );
   Image2 -> Visible = false;
   Image1 -> Visible = true;

   RoundRect1 -> Visible = true;
       RoundRect2 -> Visible = false;
   RoundRect3 -> Visible = false;
   RoundRect4 -> Visible = false;
   int n;
   String str_1;
   x++;
   if ( x == 2 ) {
   n = StrToInt ( Edit1 -> Text );
   if ( n < 20 && n > 0 ) {
verificaTabuada ( n );
Image2 -> Visible = true;
RoundRect3 -> Visible = true;
RoundRect1 -> Visible = false;
RoundRect2 -> Visible = false;

   }
   else {
   Edit1 -> Text = " ";
  x = 0;
   }
   x = 0;
}

}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect1MouseEnter ( TObject *Sender ) {
RoundRect1 -> Visible = false;
RoundRect2 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect2MouseLeave ( TObject *Sender ) {
   if ( x == 1 ) {
RoundRect2 -> Visible = false;
RoundRect1 -> Visible = true;
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect3MouseEnter ( TObject *Sender ) {
RoundRect3 -> Visible = false;
RoundRect4 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect4MouseLeave ( TObject *Sender ) {
if ( x == 0 ) {
RoundRect4 -> Visible = false;
RoundRect3 -> Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect4Click ( TObject *Sender ) {
FormShow ( Sender );
Edit1 -> SetFocus ( );
Edit1 -> Text = " ";
Label1 -> Text = " ";
}
//---------------------------------------------------------------------------


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Objects.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TLabel *Label1;
TImage *Image1;
TImage *Image2;
TRoundRect *RoundRect1;
TRoundRect *RoundRect2;
TRoundRect *RoundRect3;
TRoundRect *RoundRect4;
void __fastcall FormShow ( TObject *Sender );
void __fastcall Label_Manual ( TObject *Sender );
void __fastcall RoundRect1MouseEnter(TObject *Sender);
void __fastcall RoundRect2MouseLeave(TObject *Sender);
void __fastcall RoundRect3MouseEnter(TObject *Sender);
void __fastcall RoundRect4MouseLeave(TObject *Sender);
void __fastcall RoundRect4Click(TObject *Sender);

private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif