quinta-feira, 13 de agosto de 2020

FMX - apagando string em matriz bidimensional

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




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

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

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

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

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

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

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

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

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

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

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

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

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

Nenhum comentário:

Postar um comentário

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