terça-feira, 12 de novembro de 2019

Lendo arquivo de texto - objeto TScrollBox

Aqui está um exemplo de como usar o componente
TScrollBox para apresentar os dados de um arquivo.


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

#include <vcl.h>
#pragma hdrstop
#define SI_ZE 450
#include "Unit1.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 = 16;
    Canvas -> Font -> Name = "Arial";
    Canvas -> Pen -> Color = clRed;
    Canvas -> Rectangle ( 5, 5, 590, 290 );
    Canvas -> Pen -> Width = 10;
    Canvas -> Font -> Color = clRed;
    Canvas -> TextOut ( 60, 12, "C++ BUILDER - LENDO UM ARQUIVO DE TEXTO" );
    String str_1 = " ";
    FILE *arq;
    char **no_me;
    no_me = ( char** ) malloc ( SI_ZE * sizeof ( char* ) );
    int c = 0, i;
    //C:\Users\ManMachine\Downloads\Lendo arquivo de texto  (ScrollBox)
        arq = fopen ( "C:\\Users\\ManMachine\\Downloads\\Lendo arquivo de texto  (ScrollBox)\\"
                "Poesias famosas.txt", "r+b" );

    if ( arq == NULL ) {
        printf ( "Problemas na abertura do arquivo " );
    }
    for ( i = 0; i < SI_ZE; i++ ) {
        no_me [ i ] = ( char* ) malloc ( SI_ZE * sizeof(char*) / 3 );
        fgets ( no_me [ i ], 80, arq );
        str_1 += i + 1;
        str_1 += "  ";
        str_1 += no_me [ i ];
    }
     Label1 -> Caption = AnsiString ( str_1 );
     free ( no_me );
     fclose ( arq );
}
//---------------------------------------------------------------------------


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

#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
    TScrollBox *ScrollBox1;
    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 = 470
  Top = 177
  HorzScrollBar.ThumbSize = 3
  HorzScrollBar.Tracking = True
  Caption = 'C++ BUILDER - COMPONENTE TScrollBox'
  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
  Visible = True
  OnPaint = OnPaint
  PixelsPerInch = 96
  TextHeight = 13
  object ScrollBox1: TScrollBox
    Left = 24
    Top = 40
    Width = 553
    Height = 241
    HorzScrollBar.Tracking = True
    VertScrollBar.Tracking = True
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clFuchsia
    Font.Height = -16
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 0
    object Label1: TLabel
      Left = 24
      Top = 3
      Width = 5
      Height = 19
      Caption = ' '
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -16
      Font.Name = 'Tahoma'
      Font.Style = [fsItalic]
      ParentFont = False
    end
  end
end

Nenhum comentário:

Postar um comentário

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