Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 31-03-2014
Avatar de eennzzoo
eennzzoo eennzzoo is offline
Miembro
NULL
 
Registrado: nov 2013
Ubicación: Argentina
Posts: 59
Poder: 11
eennzzoo Va por buen camino
Error al cargar en un StringGrid

Hola tengo el siguiente codigo, y me da este error

Cuando en el edit escribo una palabra y le doy al boton agregar se carga correctamente en el archivo txt y en StringGrid, pero si vuelvo a cargar otra palabra me da ese error. Pero en el archivo txt si se carga la palabra.

Código:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <cstdio>
using namespace std;
#pragma hdrstop

#include "agregarpelicula.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfPeliculas *fPeliculas;
#define INDEX_COL 0
int OldRowHeight;
//---------------------------------------------------------------------------
TStrings *TS2 = new TStringList;
__fastcall TfPeliculas::TfPeliculas(TComponent* Owner)
        : TForm(Owner)
{
        TS2->LoadFromFile("peliculas.txt");
        fPeliculas->Color=static_cast<TColor>(RGB(198, 119, 0));
        Label1->Color =static_cast<TColor>(RGB(198, 119, 0));
        Label2->Color =static_cast<TColor>(RGB(198, 119, 0));
        if (TS2->Count > StringGrid1->RowCount-1){
                StringGrid1->RowCount = TS2->Count+1;
        }
        StringGrid1->Cells[0][0]="Peliculas";
        StringGrid1->Cells[1][0]="Cantidad";
        int j=TS2->Count;
        for(int i= 0; i<TS2->Count; i++) {
                StringGrid1->Cells[0][j]=TS2->Strings[i];
                j--;
        }

        //StringGrid1->FixedRows= 1;
        //StringGrid1->FixedCols= 0;
        // fijar número de filas
        //StringGrid1->RowCount=TS2->Count-1;
        // fijar número de columnas
        //TStrings *aux = new TStringList;
        //StringGrid1->ColCount= ExtractStrings(TSysCharSet()<< ',',TSysCharSet() << '\0', TS2->Strings[0].c_str(),aux);
        //delete aux;
        // obtener alto de celda predeterminado
        OldRowHeight = StringGrid1->DefaultRowHeight;
        // pasar a StringGrid
        //for(int lin=0; lin<TS2->Count; lin++){
                //StringGrid1->Rows[StringGrid1->FixedRows+lin]->CommaText= TS2->Strings[lin];
                //}
        //delete TS2;
}
//---------------------------------------------------------------------------
void __fastcall TfPeliculas::btnAgregarClick(TObject *Sender)
{
        FILE *FSave;
        char Nombre[30];
        strcpy(Nombre, editPelicula->Text.c_str());
        FSave = fopen("peliculas.txt", "a");
        if( FSave == NULL )
                {
			ShowMessage("El archivo no se pudo guardar");
			return;
		}
        fprintf(FSave, "%s\n", Nombre);
        fclose(FSave);
        TS2->LoadFromFile("peliculas.txt");
        int j=TS2->Count;
        for(int i= 0; i<TS2->Count; i++) {
                StringGrid1->Cells[0][j]=TS2->Strings[i];
                j--;
        }
        delete TS2;
}
//---------------------------------------------------------------------------
void __fastcall TfPeliculas::btnBuscarClick(TObject *Sender)
{
        /*for(int i = StringGrid1->FixedRows; i < StringGrid1->RowCount ; i++)
                if((StringGrid1->Cells[0][i] == editPelicula->Text)||(LowerCase(StringGrid1->Cells[0][i]) == editPelicula->Text)) {
                    TRect Casilla;
                    StringGrid1->Canvas->Brush->Color=static_cast<TColor>(RGB(252, 210, 147));
                    Casilla= StringGrid1->CellRect(0, i);
                    StringGrid1->Canvas->FillRect(Casilla);
                    StringGrid1->Canvas->TextOut(Casilla.Left+1,Casilla.top+1,StringGrid1->Cells[0][i]);
                }  */
        TStringGrid *SG = StringGrid1;
        for(int f=SG->FixedRows; f<SG->RowCount; f++) {
                if(UpperCase(SG->Cells[INDEX_COL][f].SubString(1,editPelicula->Text.Length()))== UpperCase(editPelicula->Text)){
                        SG->RowHeights[f]= OldRowHeight; }
                else    {
                        SG->RowHeights[f]= 0;}
        }
}
//---------------------------------------------------------------------------
void __fastcall TfPeliculas::FormDestroy(TObject *Sender)
{
        delete TS2;
}
//---------------------------------------------------------------------------

void __fastcall TfPeliculas::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
        if( State.Contains(gdFixed) )
        {
        StringGrid1->Canvas->Brush->Color = static_cast<TColor>(RGB(198, 119, 0));
        StringGrid1->Canvas->Font->Color = static_cast<TColor>(RGB(0, 0, 0));
        StringGrid1->Canvas->FillRect(Rect);
        StringGrid1->Canvas->Brush->Style = bsClear;
        DrawText(StringGrid1->Canvas->Handle,StringGrid1->Cells[ACol][ARow].c_str(), StringGrid1->Cells[ACol][ARow].Length(), &Rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
        }
        if( State.Contains(gdSelected) )
        {
        StringGrid1->Canvas->Brush->Color = clWindow;
        StringGrid1->Canvas->Font->Color = static_cast<TColor>(RGB(0, 0, 0));
        StringGrid1->Canvas->FillRect(Rect);
        StringGrid1->Canvas->TextOut(Rect.Left+1,Rect.top+1,StringGrid1->Cells[ACol][ARow]);
        }

}
//---------------------------------------------------------------------------
__________________
https://www.facebook.com/riverplateoficial
Responder Con Cita
  #2  
Antiguo 31-03-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola eennzzoo.

Proba de este modo:
Código:
void __fastcall TfPeliculas::btnAgregarClick(TObject *Sender)
{
  FILE *FSave;

  if ((FSave = fopen("peliculas.txt", "a")) == NULL) {
    ShowMessage("El archivo no se pudo guardar");
    return;
  }
  fprintf(FSave,"%s\n", editPelicula->Text.c_str());
  fclose(FSave);

  TS2->LoadFromFile("peliculas.txt");
  int j=TS2->Count;
  for(int i= 0; i<TS2->Count; i++) {
    StringGrid1->Cells[0][j]=TS2->Strings[i];
    j--;
  }
  // delete TS2;  ¡¡¡ Erroneo !!! (excepcion en OnDestroy)
}
Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #3  
Antiguo 31-03-2014
Avatar de eennzzoo
eennzzoo eennzzoo is offline
Miembro
NULL
 
Registrado: nov 2013
Ubicación: Argentina
Posts: 59
Poder: 11
eennzzoo Va por buen camino
Si ahi funciona gracias. Se puede que al hacer un click en algunas de las celdas del Str¡ngGrid me los cargue en un txt a la palabra que selecione?
__________________
https://www.facebook.com/riverplateoficial
Responder Con Cita
  #4  
Antiguo 31-03-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Si, de modo similar al guardado anterior:
Código:
// Guarda celda sobre la que hizo click 
// si a la vez presionó la tecla Ctrl
void __fastcall TForm1::StringGrid1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if (Shift.Contains(ssCtrl)) {
    FILE *fp;
    TStringGrid *SG = StringGrid1;

    if((fp=fopen("peliculas.txt","a"))==NULL) {
      ShowMessage("Error al guardar celda");
      return;
    }
    fprintf(fp,"%s\n", SG->Cells[SG->Col][SG->Row].c_str());
    fclose(fp);
  }
}
Por favor en lo futuro cuando hagas una pregunta que no tiene que ver con el hilo inicial, publicala en un nuevo hilo.

Saludos y gracias por tu colaboración
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #5  
Antiguo 31-03-2014
Avatar de eennzzoo
eennzzoo eennzzoo is offline
Miembro
NULL
 
Registrado: nov 2013
Ubicación: Argentina
Posts: 59
Poder: 11
eennzzoo Va por buen camino
Ok no sabia. Gracias.
__________________
https://www.facebook.com/riverplateoficial
Responder Con Cita
  #6  
Antiguo 01-04-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola eennzzoo.

No te preocupes, a todos nos ha pasado.

Tal vez te pueda interesar acceder al archivo usando sintáxis privativa de C++:
Código:
...
#include<fstream>
...

void __fastcall TForm1::StringGrid1MouseDown(TObject *Sender,
  TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if(Shift.Contains(ssCtrl)) {
    TStringGrid *sg = StringGrid1;
    std::fstream fs("peliculas.txt", std::fstream::out | std::fstream::app);
    fs << sg->Cells[sg->Col][sg->Row].c_str();
    fs.close();
  }
}
Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Cargar datos en StringGrid en tiempo de ejecucion!! ezequiel913 Varios 5 02-07-2011 23:37:42
Cargar imágenes en celdas de StringGrid dependiendo de una consulta en tiempo de eje gulder Varios 8 11-12-2008 20:58:45
Error al Cargar una Dll de C# jangel_ramirezm Varios 7 16-04-2008 00:28:43
STringGrid: cargar archivo previamente guardado. amadis OOP 4 01-05-2007 23:52:30
Error al cargar sql bbjb SQL 4 10-02-2006 17:42:31


La franja horaria es GMT +2. Ahora son las 11:19:36.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi