| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Alpha120 Lt


Registrado: 11 Mar 2007Mensajes: 99Ubicación: Sevilla, España
|
Publicado: Jue 29 Mar, 2007 7:54 pm Asunto: Guardar StringGrid |
|
|
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++)
Gracias. _________________ Saludos, Alpha. |
|
| Volver arriba |
|
 |
Jumanor Lt


Registrado: 28 Feb 2003Mensajes: 91Ubicación: tacna-Peru
|
Publicado: Vie 30 Mar, 2007 1:47 am Asunto: |
|
|
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 |
|
 |
Alpha120 Lt


Registrado: 11 Mar 2007Mensajes: 99Ubicación: Sevilla, España
|
Publicado: Vie 30 Mar, 2007 5:57 am Asunto: |
|
|
Muchas gracias. La función Add, en qué librería está???  _________________ Saludos, Alpha. |
|
| Volver arriba |
|
 |
Jumanor Lt


Registrado: 28 Feb 2003Mensajes: 91Ubicación: tacna-Peru
|
Publicado: Vie 30 Mar, 2007 10:55 pm Asunto: pascal |
|
|
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 |
|
 |
Alpha120 Lt


Registrado: 11 Mar 2007Mensajes: 99Ubicación: Sevilla, España
|
Publicado: Sab 31 Mar, 2007 12:45 am Asunto: |
|
|
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  _________________ Saludos, Alpha. |
|
| Volver arriba |
|
 |
|