Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

array from db table

Posted on 2000-03-29
5
Medium Priority
?
140 Views
Last Modified: 2010-04-04
Can someone please give me a code example of getting data from a table and putting it into a two dimensional array.

Thank You.
0
Comment
Question by:fiinfo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 150 total points
ID: 2668193
Sample bellow is applicable in case your know maximum fields and records of a table. In other case use dynamic arrays instead static.
-------
const MaxRecNo = 100;
        MaxFldNo=20;

var A : array[0..MaxRecNo-1,0..MaxFldNo-1] of variant;

procedure ....
var I,N : integer;
begin
    Table1.Open;
    N:=0;
    while not Table1.EOF do
    begin
       for I:=0 to Table1.Fields.Count-1 do A[N,I]:=Fable1.Fields[I].AsVariant;
       inc(N);
       Table1.Next;
    end;
   Table1.Close;
end;
--------

Cheers,
Igor.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2668213
Lets assume we have a table with fields "X", "Y",and "Value", integer, integer and double respectively, then you could do this;

var
  TheArray = Array[1..MaxX, 1..MaxY] of Double;

Table.First;
while not Table.eof do
  begin
    TheArray[Table.FieldByName('X').AsInteger,
             Table.FieldByName('Y').AsInteger] := Table.FieldByName('Value').AsFloat; // or AsDouble...
    Table.Next;
  end;

Cheers,

Raymond.


0
 

Author Comment

by:fiinfo
ID: 2671274
I'm sorry, I don't understand your example (my fault not yours I'm sure).
My solution:

procedure....
var
  myArray : array of array of variant;
  F, R, n, i: Integer;
begin
  table1.open;
  table1.first;
  R := table1.recordcount;
  F := table1.fieldcount;
  setLength(myArray, R, F);
  while not Table1.EOF do
    begin
        for n := 0 to Table1.RecordCount-1 do
        begin
            for i:= 0 to Table1.FieldCount-1 do
            begin
                myArray[n, i]:= Table1.fields[i].AsVariant;
                listbox1.items.add(myArray[n,i]);//just to look at the result
            end;
            table1.next;
        end;
    end;
table1.close;
end;

If you can see a problem with this solution, I'd appreciate your input.
Thank YOu.

0
 
LVL 9

Expert Comment

by:ITugay
ID: 2672486
Rob has shown you the way how to store and retrieve two-dimension array of float values into/from table.

Now about YOUR solution. It's look like my sample but only with dynamic array. And it's seems like you have it. You looking for what? For bugs? For another way?

Igor.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2672488
Not Rob, sorry Raymond.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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