Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

Guardar StringGrid

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: Guardar StringGrid Responder citando

Saludos, encontré este código en Delphi, y bueno, si alguien se podría tomar la molestia de traducirlo a C++ Builder.

Código:
// Para guardar
var
  i: integer;
begin
  with TStringList.Create do
  try
    for i:= 0 to StringGrid1.RowCount - 1 do
      Add(StringGrid1.Rows[i].CommaText);
    SaveToFile('d:\1.txt');
  finally
    Free;
  end;
end;


//Para recuperar
var
  i: integer;
begin
  with TStringList.Create do
  try
    LoadFromFile('d:\1.txt');
    StringGrid1.RowCount:= Count;
    for i:= 0 to Count - 1 do
      StringGrid1.Rows[i].CommaText:= Strings[i];
  finally
    Free;
  end;
end;


Supongo que es fácil, a ver si logro implementarlo en C++ yo solo. Así tal como está, supongo que dará error (lógico porque no es código en C++)
Laughing
Gracias.
_________________
Saludos, Alpha.
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor
Mensaje    Asunto: Responder citando

HOlas:

Aver si te ayuda

Código:

//PARA GUARDAR
void __fastcall TForm2::btn1Click(TObject *Sender)
{
TStringList *Lista=new TStringList;
   try{
      for(int i=0;i<StringGrid1>RowCount-1;i++)
      {
       Lista->Add(StringGrid1->Rows[i]->CommaText);
       Lista->SaveToFile("d:\\1.txt");
      }
     }
   __finally
     {
     delete Lista;
     }

}
//---------------------------------------------------------------------------

//PARA RECUPERAR
void __fastcall TForm2::btn2Click(TObject *Sender)
{
   TStringList *Lista=new TStringList;
   try{
       Lista->LoadFromFile("d:\\1.txt");
       StringGrid1->RowCount=Lista->Count;
      for(int i=0;i<Lista>Count-1;i++)
      {
       StringGrid1->Rows[i]->CommaText=Lista->Strings[i];
      }
     }
   __finally
     {
     delete Lista;
     }
}



Saludos
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email Visitar sitio web del autor MSN Messenger
Mensaje    Asunto: Responder citando

Muchas gracias. La función Add, en qué librería está??? Confused
_________________
Saludos, Alpha.
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor
Mensaje    Asunto: pascal Responder citando

HoLaS:::::

Add es un metodo de clase

Bueno tambien podrias haber creado una libreria en pascal y hacer uso del compilador de pascal que trae consiguo el Builder para que te genere el hpp respectivo.

Código:

unit Unit3;
interface
uses Grids,Classes;

procedure Guardar(StringGrid1: TStringGrid);
procedure Recuperar(StringGrid1: TStringGrid);


implementation
procedure Guardar(StringGrid1: TStringGrid);
var
  i: integer;
begin
  with TStringList.Create do
  try
    for i:= 0 to StringGrid1.RowCount - 1 do
      Add(StringGrid1.Rows[i].CommaText);
    SaveToFile('d:\1.txt');
  finally
    Free;
  end;
end;

procedure Recuperar(StringGrid1: TStringGrid);

//Para recuperar
var
  i: integer;
begin
  with TStringList.Create do
  try
    LoadFromFile('d:\1.txt');
    StringGrid1.RowCount:= Count;
    for i:= 0 to Count - 1 do
      StringGrid1.Rows[i].CommaText:= Strings[i];
  finally
    Free;
  end;
end;
end.


1) Una vez creada añade en el proyecto CBuilder el archivo Uni3.pas.
2) Compila el pas y el compilador te generara un archivo Unit3.hpp que lucira como sigue:

Código:

// Borland C++ Builder
// Copyright (c) 1995, 2005 by Borland Software Corporation
// All rights reserved

// (DO NOT EDIT: machine generated header) 'Unit3.pas' rev: 10.00

#ifndef Unit3HPP
#define Unit3HPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member functions
#pragma pack(push,8)
#include <System>   // Pascal unit
#include <Sysinit>   // Pascal unit
#include <Grids>   // Pascal unit
#include <Classes>   // Pascal unit

//-- user supplied -----------------------------------------------------------

namespace Unit3
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
extern PACKAGE void __fastcall Guardar(Grids::TStringGrid* StringGrid1);
extern PACKAGE void __fastcall Recuperar(Grids::TStringGrid* StringGrid1);

}   /* namespace Unit3 */
using namespace Unit3;
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif   // Unit3


3)Si queres utizar las funciones(stando logicamente en el builder) simplemente tendra q añadir Unit3.hpp

Suerte a veces es mas facil de ste modo que traducirlo directamente...


SaLuDoS!!!!!!!
_________________
Es dificil decir q es imposible xq el sueño de ayer es la esperanza de hoy y la realidad d mañana
Volver arriba
Ver perfil de usuario Enviar mensaje privado Enviar email Visitar sitio web del autor MSN Messenger
Mensaje    Asunto: Responder citando

Ya lo implementé en Builder a base de código, así lo entiendo mejor para modificarlo si lo necesito, pero gracias por enseñarme ese otro método.

Entonces el código Delphi se puede compilar con pascal? no tenia ni idea. Por eso, gracias a ti ya se algo más de este mundillo Wink
_________________
Saludos, Alpha.
Volver arriba
Ver perfil de usuario Enviar mensaje privado Visitar sitio web del autor
Mostrar mensajes de anteriores:   
Cambiar a:  
No puedes publicar temas nuevos en este foro
No puedes responder a temas en este foro
No puedes editar tus mensajes en este foro
No puedes borrar tus mensajes en este foro
No puedes votar en las encuestas de este foro


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.