Solved

looking 4 software that convert TDBGrid 2 Ascii

Posted on 2004-04-14
14
197 Views
Last Modified: 2010-04-05
hellow im looking 4 a software that convert TDBGrid to ascii file. i need to define the fields b4 the converting.
i need to change the formats of the fields b4 the converting.
for example date data  dd/mm/yyyy will  set  as yyyymmdd in the ascii file
0
Comment
Question by:croudo
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10822780

   Take a look at this - it is export to Excel, you can take the same idea to export to text dilimited file.

   http://www.swissdelphicenter.ch/en/showcode.php?id=1427
0
 

Author Comment

by:croudo
ID: 10822804
i know that site but he not let me change the format of the field b4 export :(
0
 
LVL 17

Expert Comment

by:mokule
ID: 10823074
Do it Yourself

procedure TForm1.Export;
var
  i: integer;
begin
  DBGrid1.DataSource.DataSet.First;
  DBGrid1.DataSource.DataSet.DisableControls;
  while not DBGrid1.DataSource.DataSet.Eof do
    begin
    for i := 0 to DBGrid1.Columns[i].Count-1
      begin
      if DBGrid1.Columns[i].FieldName = 'something' then
        begin
        // do desired format and export
        end;
      if DBGrid1.Columns[i].FieldName = 'something else' then
        begin
        // do desired format and export
        end;
      end;
    DBGrid1.DataSource.DataSet.Next;
    end;
  DBGrid1.DataSource.DataSet.EnableControls;
end;
0
 

Author Comment

by:croudo
ID: 10823119
thankss but i need some thing modular for users.
0
 

Expert Comment

by:augustose
ID: 10826743
try with this code, call me if not work


unit ugridtotext;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, Grids, DBGrids, IBCustomDataSet, IBDatabase;

type
  TForm1 = class(TForm)
    IBDatabase1: TIBDatabase;
    IBTransaction1: TIBTransaction;
    DataSet1: TIBDataSet;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure Exportgrid;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Exportgrid;
var
  i: integer;
  F: TextFile;
  ok : boolean;
begin
  ok := False;
  AssignFile(F, ExtractFilePath(Application.ExeName) + 'Dbgrid.csv');   { File selected in dialog box }
  try
    Append(F);
    ok := True;
  except
    try
      Rewrite(F);
      ok := True;
    except
    end;
  end;

  DBGrid1.DataSource.DataSet.First;
  DBGrid1.DataSource.DataSet.DisableControls;
  while not DBGrid1.DataSource.DataSet.Eof do
  begin
    for i := 0 to DBGrid1.DataSource.DataSet.fields.Count-1 do
    begin
      Write(f,DBGrid1.DataSource.DataSet.Fields[i].AsString);
      Write(F, ',' );
    end;
    WriteLn(F, '' );
    DBGrid1.DataSource.DataSet.Next;
  end;

  DBGrid1.DataSource.DataSet.EnableControls;
  CloseFile(F);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Exportgrid;
end;


end.



0
 
LVL 11

Expert Comment

by:calinutz
ID: 10828464
listening
0
 

Author Comment

by:croudo
ID: 10830393
hi augustose its works.
but i need some thing that let me set the format of each field.
some field need to be cut from x position to y position and some need to be in ansi, dont u know some thing that all ready working?.
thankss 4 the care.
croudo assaf
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10850027
Why dont u use a Report for example Qreport ... and try to export it in a text file.. u can desing all ur field masks...


Its easy fast ...

0
 

Author Comment

by:croudo
ID: 10852202
hi non zero
how can i export qrp format to text format and how can i change desing all my masks field on fly???
that a lot croudo assaf.
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10854210
U get data in to ur DBGrid from a dataset rite ?

Create a form, add a report  and a exporter like Txt exporter in desing time..

In Run time..
 When u want to export ur data,
  1. Assign ur DbGrids dataset as ur report data set.
  2. Add fields that ur using in ur Dbgrid to the report
  3. Set mask properties of the fields same as ur dbgrid.
  4. Prepare report ..
  5. Export ur data
0
 

Author Comment

by:croudo
ID: 10856903
there r many components of what u say but it not fit to me.
i dont want to export the field as they show in the dbGrid i want to format them in my self.
thankss croudo  assaf.
0
 
LVL 19

Accepted Solution

by:
Melih SARICA earned 125 total points
ID: 10857191
Its not important .. U can either format ur fields as they r in the DBgrid or not..

U can format ur fields at runtime how ever u want.. ıt depends on u ..

If ur fields ll ave the same format everytime u want to export..

Cretae a table that ll collect every field in ur Database and their Masks..
or Just add the fields that ll ave special Format settings..

During the export process check this table if it has special Format option, and apply this format to the report builder...
or Use the original format and apply this to ur report field..

Or.. At runtime with the report builders runtime Builder u can build ur report with selected fields and selected firlds mask/format ..

Thats it..

0
 

Expert Comment

by:augustose
ID: 10864712
try using
free repport
that is the way
0
 

Author Comment

by:croudo
ID: 10866621
what is free report??? :(
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 95
build html 5 client that connect to indy Tidtcpserver 3 356
How to debug For loops? 3 46
Performance of SQL statement 37 100
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now