sábado, 2 de fevereiro de 2019

C++ Builder - ordenando vetores

Aproveitando a função sorteia,
que já usamos muitas vêses,
carregamos um vetor de inteiro
de números de ( 0 à 9 ), 
totalmente desordenados,
mas fazendo uso da função qsort (),
do C, podemos ordenar o mesmo vetor,
imprimindo um número por vez,
criando uma nova sequência a cada
pressionamento do botão ok da caixa
de mensagem destinada ao usuário.







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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
#include <time.h>
#define tam 10
int Qsort_Ord ( const void *a, const void *b ) {
return ( strcmp ( ( char * ) a, ( char * ) b ) );
}
//---------------------------------------------------------------------------
void Sorteia ( int *A, int *vet ) {
int i, j, aut, t;
srand ( time ( NULL ) );
A = ( int* ) malloc ( tam * sizeof ( int ) );
for ( i = 0; i < tam; i++ ) {
do {
do {
t = rand ( ) % tam;
break;
} while ( 1 );
aut = 0;
for ( j = 0; j < tam; j++ )
if ( t == A [ j ] )
aut = 1;
if ( aut == 0 ) {
A [ i ] = t;
}
} while ( aut == 1 );
}
for ( i = 0; i < tam; i++ ) {
vet [ i ] = A [ i ];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnPaint ( TObject *Sender ) {
Canvas -> Font -> Size = 16;
Canvas -> Font -> Name = "Arial";
Canvas -> Pen -> Color = clYellow;
Canvas -> Pen -> Width = 10;
Canvas -> Rectangle ( 05, 05, 595, 295 );
SetTextColor ( Canvas->Handle, RGB ( 255, 25, 2 ) );
Canvas -> TextOut ( 120, 20, "C++ BUILDER - ORDENANDO VETORES" );
String str_1;
String str_2;
int vet [ tam ];
int b = 1;
int i, x = 0;
int *A;
A = ( int* ) malloc ( tam * sizeof(int) );
Sorteia ( A, vet );
Canvas -> Font->Color = clBlack;
Canvas -> TextOut ( 60, 100, "Vetor desordenado" );
Canvas->Font->Color = clRed;
for ( i = 0; i < tam; i++ ) {
str_1 += vet [ i ];
str_1 += " ";
Canvas -> TextOut ( 60, 130, str_1 );
}
Canvas -> Font -> Color = clBlack;
Canvas -> TextOut ( 360, 100, "Vetor ordenado" );
Canvas -> Font -> Color = clRed;
for ( i = 0; i < tam; i++ ) {
do {
qsort ( ( void * ) vet, 10, sizeof ( vet [ 0 ] ), Qsort_Ord );
b = vet [ i ];
i++;
x++;
MessageDlgPos( L"Pressione o botão OK Para ordenar\n"
"O vetor, imprimindo um número de cada vez",
mtInformation, TMsgDlgButtons() << mbOK, 0, 290, 430 );
str_2 += vet [ b ];
str_2 += " ";
Canvas -> TextOut ( 340, 130, str_2 );
} while ( x < tam );
i = i - 1;
}
Canvas -> Font -> Style = TFontStyles() << fsBold << fsUnderline << fsItalic ;
Canvas -> Font -> Color = clBlue;
Canvas -> TextOut ( 200, 220, "Por: Samuel Lima " );
Canvas -> Font -> Style = TFontStyles() << fsBold << fsItalic ;
Canvas -> Font -> Color = clGreen;
Canvas -> TextOut ( 200, 250, "sa_sp10@hotmail.com" );
free ( A );

}

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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#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
void __fastcall OnPaint(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------

#endif


object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'C++ BUILDER - ORDENANDO VETORES'
  ClientHeight = 300
  ClientWidth = 600
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnPaint = OnPaint
  PixelsPerInch = 96
  TextHeight = 13
end

C++ Builder - preenchendo listbox

Criamos dois ListBox, sendo que o primeiro
já vem carregado pela matriz 
bidimensional de string char nomes [ ][ ];
que poderia ser de uma única dimensão,
mas preferi assim.
A função Sorteia ( ), com seus dois parâmetros,
inicializa um contador randômico,
mas elimina números repetidos,
isto é fundamental, para que os nomes não
se repitam dentro do listbox2, 
na hora da seleção aleatória,
que acontece pressionando o botão "OK",
da caixa de mensagem utilizada pelo usuário.




 



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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
#include <time.h>
#define tam 10

void Sorteia ( int *vet ) {
 int i, r, temp;
   srand ( time ( NULL ) );
    for ( i = 0; i < tam; i++ ) {
r = rand ( ) % tam;
temp = vet [ i ];
vet [ i ] = vet [ r ];
vet [ r ] = temp;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnPaint ( TObject *Sender ) {

 char nomes [ 10 ] [ 16 ] =
     { "Éder Costa",
   "Humberto Gomes",
   "Dijalma Lacerda",
   "Caroline Silva",
   "Igor Gonçalves",
   "Bruna Carla ",
   "Fábio Quadros",
   "Geany Barros",
   "Ana Célia",
   "Jaqueline Vega" };
 int vet [ tam ];
 int b = 9;
 int i, x = 0;
for ( i = 0; i < tam; i++ ) {
vet [ i ] = i;
}
 Sorteia ( vet );
 for ( i = 0; i < tam; i++ ) {
  ListBox1 -> Items -> Add ( nomes [ i ] );
 }
 for ( i = 0; i < tam; i++ ) {
  do {
  b = vet [ i ];
  i++;
  x++;
   MessageDlgPos ( L"Pressione no botão OK Para selecionar\n"
"Um nome aleatoriamente\n"
     "Para ser inserido no ListBox2",
     mtInformation, TMsgDlgButtons() << mbOK, 0, 290, 430 );
ListBox2 -> Items -> Add ( nomes [ b ] );
} while ( x < tam );
  i = i - 1;
  }
}
//---------------------------------------------------------------------------


#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TListBox *ListBox1;
TListBox *ListBox2;
void __fastcall OnPaint(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------

#endif


object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'C++ BUILDER - PREENCHENDO LISTBOX'
  ClientHeight = 300
  ClientWidth = 600
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnPaint = OnPaint
  PixelsPerInch = 96
  TextHeight = 13
  object ListBox1: TListBox
    Left = 24
    Top = 64
    Width = 217
    Height = 193
    Color = clGradientActiveCaption
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = [fsItalic]
    ItemHeight = 19
    ParentFont = False
    TabOrder = 0
  end
  object ListBox2: TListBox
    Left = 352
    Top = 64
    Width = 217
    Height = 193
    Color = clSilver
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = [fsItalic]
    ItemHeight = 19
    ParentFont = False
    TabOrder = 1
  end

end

sexta-feira, 1 de fevereiro de 2019

C++ Builder - Vetor invocando vetor

Na função de eventos OnPaint criei e inicializei 
dois vetores de números inteiros, à saber:
int vetor [ tam ] = { ...}; que recebe seu tamanho
pré-definido pela Macro tam,
e int vet [ dim ] = { ...}; que recebe seu tamanho
pré-definido pela Macro dim.
int vetor [ ] foi passado como parâmetros para a função
emb_lhar ( int vetor [ tam ] ) para que seus
nove elementos sequenciais sejam embaralhados,
mas a quantidade de números embaralhados que serão
imprimidos no vídeo é definida por cada um dos
quatro elementos de int vet [ ] = {...};
Porém não é de qualquer maneira a chamada destes
números que serão à quantidade dos números apresentados
é totalmente aleatória, por isto msmo dei este título
estranho ao programa:
C++ BUILDER - VETOR INVOCANDO VETOR,
Se quiser saber mais click na imagem e veja os códigos
do programa, copie e cole no seu Embarcadero,
Se não conseguir compilar me peça o link do projeto
completo para download, que estou pronto
a disponibilizá-lo para estudos.


//---------------------------------------------------------------------------
//Unit1.cpp
#include <vcl.h>
#include <conio.h>
#pragma hdrstop
#define tam 9
#define dim 4
#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->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";
Canvas->Font->Size = 20;
Canvas->Font->Color = clSkyBlue;
Canvas->TextOut ( 200, 256, "MUITO OBRIGADO" );
SetBkMode ( Canvas->Handle, TRANSPARENT );
Canvas->Font->Color = clBlue;
Canvas->TextOut ( 200, 250, "MUITO OBRIGADO" );
}
void emb_lhar ( int vetor [ tam ] ) {
int i, temp;
int y = y;
srand (time ( NULL ) );
for ( i = 0; i < tam; i++ ) {
y = rand ( ) % tam;
temp = vetor [ i ];
vetor [ i ] = vetor [ y ];
vetor [ y ] = temp;
}
}

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

void __fastcall TForm1::OnPaint ( TObject *Sender ) {
Canvas->Font->Size = 18;
Canvas->Font->Name = "Garamond";
Canvas->Font->Color = clRed;
Canvas->Font->Name = "Garamond";
Canvas->Pen->Width = 10;
Canvas->Rectangle ( 05, 05, 595, 295 );
SetTextColor ( Canvas->Handle, RGB ( 255, 25, 2 ) );
Canvas->TextOut ( 40, 20, "C++ BUILDER - VETOR INVOCANDO VETOR" );
String str_1 = " ";
String str_2 = " ";
String str_3 = " ";
Canvas->Font->Color = clRed;
int vetor [ tam ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int vet [ dim ] = { 2, 3, 4, 5 };
int b;
int a = 1;
int i, x = 0;
emb_lhar ( vet );
for ( i = 0; i < tam; i++ ) {
for ( i = 0; i < dim; i++ ) {
do {
str_2 = " ";
a = vet [ i ];
str_1 = a;
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 140, 70, "Imprimindo " );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 270, 70, str_1 );
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 300, 70, "elementos " );
emb_lhar ( vetor );
for ( b = 0; b < a; b++ ) {
str_2 += vetor [ b ];
}
i++;
x++;
str_3 = ( x + 0 );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 140, 130, str_3 + "ª");
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 170, 130, "Impressão" );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 400, 70, "                      " );
Canvas->TextOut ( 400, 70, str_2 );
Sleep ( 2000 );
if ( ( x + 0 ) == 9 ) {
Informe ( Sender );
Sleep ( 4000 );
exit ( 0 );
}
break;
str_2 = " ";
} while ( 1 );
i = i - 1;
}
}
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
//Unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall OnPaint(TObject *Sender);
    void __fastcall Informe ( TObject *Sender );
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------

#endif


object Form1: TForm1
  Left = 342
  Top = 165
  Caption = 'C++ BUILDER - VETOR INVOCANDO VETOR'
  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 = OnPaint
  PixelsPerInch = 600
  TextHeight = 13

end

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

FMX - Matriz bidimensional de caracteres






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

#include <fmx.h>
#pragma hdrstop

#include "OnShow.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#define tam 20
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 ( TComponent* Owner ) :
TForm ( Owner ) {
}

void __fastcall TForm1::OnShow ( TObject *Sender ) {
String str_1 = "";
String str_2 = "";
Label1->Text = "Memo - Matriz bidimensional de caracteres";
char caracteres [ 5 ] [ 5 ] =
  {{ 'A', 'B', 'C', 'D', 'E'},
  { 'F', 'G', 'H', 'I', 'J' },
  { 'L', 'M', 'N', 'O', 'P' },
  { 'Q', 'R', 'S', 'T', 'U' },
  { 'V', 'X', 'Z', 'Y', 'K' } };
int i, j;
for ( i = 0; i < 5; i++ ) {
if ( i % 1 == 0 )
str_1 += "\n";
for ( j = 0; j < 5; j++ ) {
if ( j % 1 == 0 )
str_1 += "\t";
str_1 += caracteres  [  i  ]  [  j  ];
}
}
Memo1->Text = Memo1->Text + AnsiString ( str_1 );
Memo1->SelStart = 0;
Text1->Text = "Por: Samuel Lima";
}

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

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

#ifndef OnShowH
#define OnShowH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Objects.hpp>
#include <FMX.Types.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Memo.hpp>
#include <FMX.ScrollBox.hpp>
#include <FMX.StdCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
 TLabel *Label1;
 TRoundRect *RoundRect1;
 TText *Text1;
TMemo *Memo1;
TRectangle *Rectangle1;
TRectangle *Rectangle2;
 void __fastcall OnShow(TObject *Sender);


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

#endif


object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Memo - Matriz bidimensional de caracteres'
  ClientHeight = 302
  ClientWidth = 600
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  OnShow = OnShow
  DesignerMasterStyle = 0
  object Label1: TLabel
    StyledSettings = [Family]
    Position.X = 128.000000000000000000
    Position.Y = 8.000000000000000000
    Size.Width = 393.000000000000000000
    Size.Height = 25.000000000000000000
    Size.PlatformDefault = False
    TextSettings.Font.Size = 18.000000000000000000
    TextSettings.Font.StyleExt = {00070000000200000004000000}
    TextSettings.FontColor = claCrimson
    TabOrder = 1
  end
  object RoundRect1: TRoundRect
    Fill.Kind = None
    Position.X = 184.000000000000000000
    Position.Y = 232.000000000000000000
    Size.Width = 249.000000000000000000
    Size.Height = 41.000000000000000000
    Size.PlatformDefault = False
    Stroke.Color = claDarkorchid
    Stroke.Thickness = 2.000000000000000000
  end
  object Text1: TText
    Position.X = 192.000000000000000000
    Position.Y = 240.000000000000000000
    Size.Width = 225.000000000000000000
    Size.Height = 25.000000000000000000
    Size.PlatformDefault = False
    TextSettings.Font.Size = 22.000000000000000000
    TextSettings.Font.StyleExt = {00040000000200000004000000}
    TextSettings.FontColor = claBlue
  end
  object Memo1: TMemo
    Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
    DataDetectorTypes = []
    Position.X = 120.000000000000000000
    Position.Y = 40.000000000000000000
    Size.Width = 385.000000000000000000
    Size.Height = 169.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 2
    Viewport.Width = 381.000000000000000000
    Viewport.Height = 165.000000000000000000
  end
  object Rectangle1: TRectangle
    Fill.Kind = None
    Position.X = 120.000000000000000000
    Position.Y = 40.000000000000000000
    Size.Width = 385.000000000000000000
    Size.Height = 169.000000000000000000
    Size.PlatformDefault = False
    Stroke.Color = claAqua
    Stroke.Thickness = 4.000000000000000000
  end
  object Rectangle2: TRectangle
    Fill.Kind = None
    Size.Width = 601.000000000000000000
    Size.Height = 305.000000000000000000
    Size.PlatformDefault = False
    Stroke.Color = claHotpink
    Stroke.Thickness = 10.000000000000000000
  end
end

quinta-feira, 24 de janeiro de 2019

FMX - Matriz bidimensional de string

Aqui está mais um exemplo de uso
do objeto memo do C++ Builder.
Neste exemplo o memo é carregado 
por uma matriz bidimensional de string,
Note que um scrollbar horizontal e
vertical foi ativado para facilitar a leitura
do texto que possui mais de 60 linhas.




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

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

void __fastcall TForm1::OnShow(TObject *Sender)
{
  Label1 ->Text = "Memo - Matriz bidimensional de string";
 char texto [ 63 ] [ 45 ] =  {
"Debaixo dumas mui formosas tamareiras,      \n",
"Estando já Berseba na escuridão.            \n",
"As aves escutando, entre as roseiras,       \n",
"Se vê andar o patriarca Abraão.             \n",
"Seu coração perante Deus está aflito,       \n",
"Pois quer que O sirvamos sem murmuração;    \n",
"E por amor pergunta ao Senhor bendito:      \n",
"O meu amado filho queres Tu, então?         \n",
"                                            \n",
"A voz de Jeová potente é ouvida:            \n",
"O teu Isaque oferece para Mim,              \n",
"Embora fiques com tu'alma dolorida,         \n",
"Pois te abençoo se fizeres tu assim.        \n",
"De abatido Abraão se torna forte            \n",
"E Canta hinos, pois com fé medita já:       \n",
"Deus pode o meu filho libertar da morte!    \n",
"E não temendo, segue para Moriá.            \n",
"                                            \n",
"Ao pé do monte do supremo sacrifício,       \n",
"Profunda duvida entrou em Abraão:           \n",
"Irei perder da minha vida o beneficio?      \n",
"E triste começou subir com lentidão,        \n",
"Pois ia dar, do coração a esperança         \n",
"- No seu outono, sacrifício duma flor,      \n",
"Assim levou o seu cordeiro à matança,       \n",
"Em obediência ao mandato do Senhor.         \n",
"                                            \n",
"Isaque com a lenha, presto vai na frente,   \n",
"Oh! Quanto é formoso para Abraão!           \n",
"Mas eis que volta p'ra seu pai suavemente   \n",
"E lhe dirige esta interrogação:             \n",
"O fogo e a lenha estou vendo que trouxemos, \n",
"Mas o cordeiro d'holocausto onde está?      \n",
"E a resposta de Abraão na Bíblia temos:     \n",
"Meu filho, Deus pra Si, Cordeiro proverá    \n",
"                                            \n",
"Chegando Abraão aonde Deus mandara,         \n",
"Fez um altar e nele a lenha arrumou:        \n",
"E a seu filho, que já dantes amarrara,      \n",
"Tomando nos seus braços sobre o altar deitou\n",
"Mas quando Abraão foi para imolá-lo,        \n",
"O Anjo do Senhor bradou-lhe desde os céus:  \n",
"A tua mão, ó não estendas p'ra matá-lo;     \n",
"Porquanto eu agora sei que temes Deus.      \n",
"                                            \n",
"Erguendo Abraão seus olhos de repente,      \n",
"Vê um cordeiro, que no mato preso está,     \n",
"E o tomando, oferece-o alegremente;         \n",
"Assim No monte do Senhor se proverá.        \n",
"A voz do Anjo é ouvida novamente;           \n",
"Diz o Senhor: Porque fizeste esta ação,     \n",
"Deveras, Eu abençoarei a tua semente,       \n",
"E nela, as nações benditas se farão.        \n",
"                                            \n",
"O nosso Isaque oferecemos com firmeza       \n",
"No Moriá onde finda o ideal,                \n",
"Pois foi ali que alcançaram fortaleza,      \n",
"Os vencedores, sob canto angelical;         \n",
"Ali, o nosso Deus jurou fidelidade,         \n",
"Também os santos se encheram de valor,      \n",
"E só teremos a perfeita santidade,          \n",
"Depois que formos para o monte do Senhor    \n" };
int i = 0;
Memo1->Text = Memo1->Text + AnsiString ( texto [ i ] );
//Memo1->Text = Memo1->Text + AnsiString("\n");
Memo1->SelStart = 0;
Text1->Text = "Por: Samuel Lima";
}

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


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Objects.hpp>
#include <FMX.Types.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Memo.hpp>
#include <FMX.ScrollBox.hpp>
#include <FMX.StdCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRectangle *Rectangle1;
TMemo *Memo1;
TLabel *Label1;
TRectangle *Rectangle2;
TRoundRect *RoundRect1;
TText *Text1;
void __fastcall OnShow(TObject *Sender);


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

#endif


object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Memo - Matriz bidimensional de string'
  ClientHeight = 300
  ClientWidth = 600
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  OnShow = OnShow
  DesignerMasterStyle = 0
  object Label1: TLabel
    StyledSettings = [Family]
    Position.X = 160.000000000000000000
    Position.Y = 16.000000000000000000
    Size.Width = 305.000000000000000000
    Size.Height = 25.000000000000000000
    Size.PlatformDefault = False
    TextSettings.Font.Size = 18.000000000000000000
    TextSettings.Font.StyleExt = {00040000000200000004000000}
    TextSettings.FontColor = claCrimson
    TabOrder = 1
  end
  object Rectangle2: TRectangle
    Fill.Kind = None
    Position.X = 176.000000000000000000
    Position.Y = 48.000000000000000000
    Size.Width = 257.000000000000000000
    Size.Height = 177.000000000000000000
    Size.PlatformDefault = False
    Stroke.Color = claCrimson
    Stroke.Thickness = 5.000000000000000000
    object Rectangle1: TRectangle
      Fill.Color = claNull
      Position.X = -176.000000000000000000
      Position.Y = -48.000000000000000000
      Size.Width = 600.000000000000000000
      Size.Height = 300.000000000000000000
      Size.PlatformDefault = False
      Stroke.Color = claAqua
      Stroke.Thickness = 10.000000000000000000
    end
    object Memo1: TMemo
      Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
      DataDetectorTypes = []
      ReadOnly = True
      StyledSettings = [Family, FontColor]
      TextSettings.Font.Size = 14.000000000000000000
      Position.X = 8.000000000000000000
      Position.Y = 8.000000000000000000
      Size.Width = 241.000000000000000000
      Size.Height = 161.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 1
      ParentShowHint = False
      ShowHint = False
      Viewport.Width = 237.000000000000000000
      Viewport.Height = 157.000000000000000000
    end
  end
  object RoundRect1: TRoundRect
    Fill.Kind = None
    Position.X = 184.000000000000000000
    Position.Y = 232.000000000000000000
    Size.Width = 249.000000000000000000
    Size.Height = 41.000000000000000000
    Size.PlatformDefault = False
    Stroke.Color = claChartreuse
    Stroke.Thickness = 2.000000000000000000
  end
  object Text1: TText
    Position.X = 200.000000000000000000
    Position.Y = 240.000000000000000000
    Size.Width = 225.000000000000000000
    Size.Height = 25.000000000000000000
    Size.PlatformDefault = False
    TextSettings.Font.Size = 22.000000000000000000
    TextSettings.Font.StyleExt = {00040000000200000004000000}
    TextSettings.FontColor = claBlue
  end

end