Solved

looking 4 software that convert TDBGrid 2 Ascii

Posted on 2004-04-14
14
203 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 164
Help on project with Soap 10 57
Delphi: Connect to running MS Outlook 4 118
DBCtrlGrid, Delphi, Scroll 8 37
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

856 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