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

quarta-feira, 23 de janeiro de 2019

C++ Builder - utilizando o objeto Memo

Quando queremos exibir textos simples
sem formatações no C++ Builder a melhor
opção é o objeto Memo.
O Memo possui diversas propriedades,
e a maioria destas propriedades são comuns
a outros componentes do C++ Builder.
Neste exemplo estamos usando apenas três,
destas propriedades que são:

Memo1->Enabled = false;
Não permite que o usuário faça qualquer
edição no texto apresentado pelo Memo.
Memo2->MaxLength = 300;
O comprimento máximo do número de caracteres
 digitados, o padrão é 0, isto é, ilimitado.
Memo2->WordWrap = true;
Quebra automática de palavras ao atingir a borda, 
se definido como verdadeiro .
Existem muitas outras propriedades,
mas para este exemplo não se fez necessário.




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

#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  =  "Por: Samuel Lima";
String str_1 = " ";
int A [ 100 ], a, i;
for ( i = 0; i < 100; i++ ) {
A [ a ] = i;
a++;
}
for ( a = 0; a < 100; a++ ) {
if ( ( a > 0 ) ) {
str_1 += " ";
}
if ( A [ a ] >= 0 && A [ a ] < 10 ) {
str_1 += ( "0" );
}
str_1 += A [ a ];
}

Memo1->Enabled = false;
Memo1->Lines->Strings [ 0 ] = "Utilizando Objeto Memo";
Memo2->MaxLength = 300;
Memo2->Lines->Strings [ 0 ] = str_1;
Memo2->WordWrap = true;
}

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

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

#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
TShape *Shape1;
TMemo *Memo1;
TMemo *Memo2;
TLabel *Label1;
void __fastcall OnPaint(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


object Form1: TForm1
  Left = 342
  Top = 219
  Caption = 'C++ Builder - utilizando Memo'
  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 = 96
  TextHeight = 13
  object Shape1: TShape
    Left = 0
    Top = 3
    Width = 601
    Height = 294
    Brush.Style = bsClear
    Pen.Color = clRed
    Pen.Width = 10
    Shape = stRoundRect
  end
  object Label1: TLabel
    Left = 232
    Top = 260
    Width = 6
    Height = 23
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -19
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Memo1: TMemo
    Left = 176
    Top = 16
    Width = 249
    Height = 25
    BorderStyle = bsNone
    Color = clLime
    Font.Charset = BALTIC_CHARSET
    Font.Color = clBlack
    Font.Height = -21
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 0
  end
  object Memo2: TMemo
    Left = 176
    Top = 47
    Width = 249
    Height = 210
    BorderStyle = bsNone
    Color = clMenuHighlight
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -17
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    TabOrder = 1
    WordWrap = False
  end
end

terça-feira, 22 de janeiro de 2019

Função sprintf - Modo gráfico








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

#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)
{
Canvas->Font->Size = 20;
Canvas->Font->Name = "Garamond";
Canvas->Font->Color = clRed;;
Canvas->TextOut ( 150, 18, "Função sprintf - Modo gráfico" );
String str_1 = " ";
String str_2 = " ";
char buf [ 50 ];
int i;
float Temp [ 8 ] = { 8.9, 9.5, 8.0, 11.8, 12.7, 7.6, 10.3, 15.4 };

     for ( i = 0; i < 8; i++ ) {
sprintf ( buf, " %.1f ", Temp [ i ] );
str_1 += " ";
str_1 += buf;
}
Canvas->Font->Size = 16;
Canvas->Font->Name = "Garamond";
Canvas->Font->Color = clBlue;;
Canvas->TextOut ( 150, 48, "Vetor de floats convertido em string" );
Canvas->Font->Color = clBlack;;
Canvas->TextOut ( 150, 78, str_1 );
Canvas->Font->Size = 20;
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 200, 160, "Por: " );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 260, 160, "Samuel Lima");
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 200, 197, "sa_sp10@hotmail.com");
Canvas->Font->Name = "Garamond";
Canvas->Font->Size = 40;
Canvas->Font->Color = clSkyBlue;
Canvas->TextOut ( 76, 236, "MUITO OBRIGADO");
SetBkMode(Canvas->Handle, TRANSPARENT);
Canvas->Font->Color = clBlue;
Canvas->TextOut ( 70, 230, "MUITO OBRIGADO");
}

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

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

#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
TShape *Shape1;
TLabel *Label1;
void __fastcall OnPaint(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


object Form1: TForm1
  Left = 342
  Top = 219
  HorzScrollBar.Color = clWhite
  HorzScrollBar.ParentColor = False
  Caption = 'Abrindo imagem com canvas'
  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 = 96
  TextHeight = 13
  object Shape1: TShape
    Left = 0
    Top = 0
    Width = 601
    Height = 297
    Brush.Style = bsClear
    Pen.Width = 10
    Shape = stRoundRect
  end
  object Label1: TLabel
    Left = 120
    Top = 22
    Width = 10
    Height = 39
    Color = clWhite
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -32
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentColor = False
    ParentFont = False
  end
end

Abrindo imagem com canvas







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

#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)
{

Form1->WindowState = wsMaximized; // amplia a janela
Graphics::TBitmap *Bitmap; // declara Bitmap
TRect ARect, A2Rect; // declara
ARect = Rect( 0, 0, 600, 300 ); // inicializa ARect determinado as coordenadas
Bitmap = new Graphics::TBitmap; // alocação dinâmica de memória para Bitmap
Bitmap->LoadFromFile("c:\\céu.bmp"); // carrega o arquivo especificado
// BrushCopy carregará o desenho substituindo as cores negras do mesmo
Form1->Canvas->BrushCopy(ARect, Bitmap, ARect, clBlack);
// desaloca a memória dinâmica
delete Bitmap;
Label1 -> Caption  =  "Abrindo imagem com canvas";
Canvas->Font->Size = 20;
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 200, 160, "Por: " );
Canvas->Font->Color = clRed;
Canvas->TextOut ( 260, 160, "Samuel Lima");
Canvas->Font->Color = clBlack;
Canvas->TextOut ( 200, 197, "sa_sp10@hotmail.com");
Canvas->Font->Name = "Garamond";
Canvas->Font->Size = 40;
Canvas->Font->Color = clSkyBlue;
Canvas->TextOut ( 76, 236, "MUITO OBRIGADO");
SetBkMode(Canvas->Handle, TRANSPARENT);
Canvas->Font->Color = clBlue;
Canvas->TextOut ( 70, 230, "MUITO OBRIGADO");
}

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

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

#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
TShape *Shape1;
TLabel *Label1;
void __fastcall OnPaint(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


object Form1: TForm1
  Left = 342
  Top = 219
  HorzScrollBar.Color = clWhite
  HorzScrollBar.ParentColor = False
  Caption = 'Abrindo imagem com canvas'
  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 = 96
  TextHeight = 13
  object Shape1: TShape
    Left = 0
    Top = 0
    Width = 601
    Height = 297
    Brush.Style = bsClear
    Pen.Width = 10
    Shape = stRoundRect
  end
  object Label1: TLabel
    Left = 120
    Top = 22
    Width = 10
    Height = 39
    Color = clWhite
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -32
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentColor = False
    ParentFont = False
  end
end