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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.