Solved

looking 4 software that convert TDBGrid 2 Ascii

Posted on 2004-04-14
14
196 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

12 Experts available now in Live!

Get 1:1 Help Now