quarta-feira, 3 de fevereiro de 2021

FMX - pesquisando string ( Highlighter )

Este programa permite uma precisa pesquisa
na carga de uma matriz bidimensional de string do C,
e o fato mais positivo foi a não necessidade de
funções nativas nem do C e nem do C++ para isto,
fizemos na mão, e aliás estes códigos já utilizamos
a muito tempo desde os tempos que rodávamos nossos
programas na tela do cmd ( Prompt de comando ).
O que deixa o programa bem dinâmico na interação
com o usuário é a capacidade de marcar as pesquisas
encontradas, (  Highlighter ), isto nos deixa muito
satisfeito e não é o primeiro em que fizemos isto. 



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

#include <fmx.h>
#pragma hdrstop
#define lin  12
#define col 45
#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
bool x = false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
TImage *Image2;
TImage *Image3;
//---------------------------------------------------------------------------
     char texto [ lin ] [ col ] = {
        "No Meio do Caminho                        ",
"Carlos Drummond de Andrade                ",
"No meio do caminho tinha uma pedra        ",
"Tinha uma pedra no meio do caminho        ",
"Tinha uma pedra                           ",
"No meio do caminho tinha uma pedra.       ",
"Nunca me esquecerei desse acontecimento   ",
"Na vida de minhas retinas tao fatigadas.  ",
"Nunca me esquecerei que no meio do caminho",
"Tinha uma pedra                           ",
"Tinha uma pedra no meio do caminho        ",
"No meio do caminho tinha uma pedra.       "};
  int i, j, t = 0;
//---------------------------------------------------------------------------
TText *Label3 [ lin ] [ col ] = { 0 };
TText *Label4 [ lin ] [ col ] = { 0 };

TRectangle *Rectangle2 [ lin ] [ col ] = { 0 };
TRectangle *Rectangle4;

  //---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 600;
Rectangle1 -> Height = 360;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;
Rectangle1 -> Fill -> Color = claWhite;
Rectangle1 -> Size -> PlatformDefault = False;
Rectangle1 -> Stroke -> Color = claBlue;
Rectangle1 -> Stroke -> Thickness = 10;
Rectangle1 -> XRadius = 15;
Rectangle1 -> YRadius = 15;

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

Button1 -> Visible = true;
    Button1 -> Width = 30;
    Button1 -> Height = 20;
Button1 -> Position -> X = 165;
Button1 -> Position -> Y = 320;
Button1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Button1 -> TextSettings -> Font -> Family = "Arial";
Button1 -> TextSettings -> Font -> Size = 16;
Button1 -> TextSettings -> FontColor = claBlue;
Button1 -> Text = "Ok";

Button2 -> Visible = false;
Button2 -> Width = 130;
Button2 -> Height = 20;
Button2 -> Position -> X = 445;
Button2 -> Position -> Y = 320;
Button2 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Button2 -> TextSettings -> Font -> Family = "Arial";
Button2 -> TextSettings -> Font -> Size = 16;
Button2 -> TextSettings -> FontColor = claBlue;
Button2 -> Text = "Limpa pesquisas";

Label1 -> Position -> X = 80;
Label1 -> Position -> Y = 275;
Label1 -> Size -> Width = 350;
Label1 -> Size -> Height = 20;
Label1 -> AutoSize = True;
Label1 -> TextSettings -> Font -> Size = 14;
Label1 -> TextSettings -> FontColor = claRed;
Label1 -> TextSettings -> Font -> Family = "Consolas";
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;

Label5 -> Position -> X = 180;
Label5 -> Position -> Y = 10;
Label5 -> Size -> Width = 300;
Label5 -> Size -> Height = 19;
Label5 -> TextSettings -> Font -> Size = 18;
Label5 -> TextSettings -> FontColor = claRed;
Label5 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
Label5 -> Text = "FMX - PESQUISANDO STRING";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Informe ( TObject *Sender ) {
  Image2 = new TImage ( this );
  Image2 -> Visible = true;
  Image2 -> Bitmap -> LoadFromFile ("Por.bmp");
  Image2 -> Parent = Form1;
  Image2 -> Height = 40;
  Image2 -> Width = 250;
  Image2 -> Position -> X = 200;
  Image2 -> Position -> Y = 310;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Limpa_Tela ( TObject *Sender ) {
  Image3 = new TImage ( this );
  Image3 -> Visible = true;
  Image3 -> Bitmap -> LoadFromFile ("FundoBranco.bmp");
  Image3 -> Parent = Form1;
  Image3 -> Height = 280;
  Image3 -> Width = 570;
  Image3 -> Position -> X = 10;
  Image3 -> Position -> Y = 30;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Imprime_Texto ( TObject *Sender ) {
for ( i = 0; i < lin; i++ ) {
for ( j = 0; j < col; j++ ) {
  Label3 [ i ] [ j ] = new TText ( this );
  Label3 [ i ] [ j ] -> Parent = Form1;
  Label3 [ i ] [ j ] -> AutoSize = True;
  Label3 [ i ] [ j ] -> TextSettings -> Font -> Family = "Consolas";
  Label3 [ i ] [ j ] -> TextSettings -> Font -> Size = 14;
  Label3 [ i ] [ j ] -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
  Label3 [ i ] [ j ] -> TextSettings -> FontColor = claBlack;
  Label3 [ i ] [ j ] -> Position -> X = 60 + ( j * 10 );
  Label3 [ i ] [ j ] -> Position -> Y = 35 + ( i * 20 );
  Label3 [ i ] [ j ] -> Text += ( texto [ i ] [ j ] );
}
}
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
   Label_Manual ( Sender );
   Imprime_Texto  ( Sender );
   Button2 -> Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click ( TObject *Sender ) {;
Limpa_Tela ( Sender );
Image2 -> Visible = false;
Button2 -> Visible = false;
FormCreate ( Sender );
Edit1 -> SetFocus ( );
}
//---------------------------------------------------------------------------


 

Nenhum comentário:

Postar um comentário

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