Array To/From Table ?

I am a delphi beginer . I got some problem in delphi .

1) I don't know how to retrieve a range of Data to array from TABLE .and how to count arange of data in table

2) and how to save a range( array ) data to TABLE

I know how to do its in FOXPRO

eg: 1)  select TABLE
            copy to array for (fields) color =red  from TABLE
     
       2) select TABLE
           append from array(array name)


HOW TO DO THIS IN DELPHI ?

THANKS
paul_801Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rwilson032697Connect With a Mentor Commented:
You can do it like this:

var
  Array[1..100] of string;
  Count : Integer;

Count := 0;
Table1.first;
while not Table1.Eof do
  begin
    Array[Count] := Table.fieldbyname['FIELD'].AsString;
    inc(Count);
    Table1.next;
  end;

Of coursewith strings you might use a tstringlist instead.

You can you the same loop to set values into the table:

Count := 0;
Table1.first;
while not Table1.Eof do
  begin
    Table.fieldbyname['FIELD'].AsString ray[Count];
    inc(Count);
    Table1.next;
  end;

If you want to restrict the records in the table you are dealing with either use a table filter (see the filter property), or use a liveresult TQuery.

Cheers,

Raymond.
0
 
kretzschmarCommented:
hmm paul_801,

can you not do it with sql like

1.
select * from table where color = 'red'

2.
must not saved separatly, if the query is requestlive

another  possibility is to use a filter like

1.
table1.filter = 'color='+quotedStr('red');
table1.filtered := true;

2.
must not saved separatly, except you will do an explicit post

meikl
0
 
rwilson032697Commented:
Yes meikl,

My second code snippet should look like this:

Count := 0;
Table1.first;
while not Table1.Eof do
  begin
    Table.fieldbyname['FIELD'].AsString ray[Count];
    inc(Count);
    Table1.Post;
    Table1.next;
  end;

Cheers,

Raymond.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kretzschmarCommented:
hi raymond,

should this
Table.fieldbyname['FIELD'].AsString ray[Count];
not be
Table.fieldbyname['FIELD'].AsString := ray[Count];

and should this
  Array[1..100] of string;
not be
  Ray : Array[1..100] of string;
//Ray is guessed

;-))
0
 
rwilson032697Commented:
gaak! Don't you hate it when that happens!

Cheers,

Raymond.
0
 
kretzschmarCommented:
yup, i hate this too ;-)
i guess you are to much in hurry
0
All Courses

From novice to tech pro — start learning today.