Recent

Author Topic: [Solved] What did I gorget in my array of array?  (Read 2902 times)

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
[Solved] What did I gorget in my array of array?
« on: September 01, 2014, 10:48:01 am »
Hello!

I try to crate a dynamic array with the help of the Query.
The Query is working fine, but the values are not copy to the array, as I want to!
No matter what I try to do, the "showmessage" is always empty!

Code: [Select]
procedure TForm1.Button2Click(Sender: TObject);
var temp: string;
count, i, y: integer;
MyReport: array of array of string;
begin
temp:= 'SELECT afatablefrim.Land, afatablefrim.Post, afatablefrim.Nummer, ';
temp:= temp + ...
temp:= temp + 'afatablefrim.Nummer, afatablefrim.Type, afatablefrim.Postfrisk;';
If SQLQuery1.Active = true then SQLQuery1.Active:= false;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add(temp);
SQLQuery1.ExecSQL;
If SQLQuery1.Active = false then SQLQuery1.Active:= true;
count:= 0;
While Not(SQLQuery1.Eof) do
      begin
      count:= count + 1;
      SQLQuery1.Next;
      end;
Showmessage ( IntToStr(count));
SetLength(MyReport,count,12);

If SQLQuery1.Active = true then SQLQuery1.Active:= false;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add(temp);
SQLQuery1.ExecSQL;
i:= 0;
While Not(SQLQuery1.Eof) do
      begin
      MyReport[i,0]:= SQLQuery1.Fields[0].asstring;
      MyReport[i,1]:= SQLQuery1.Fields[1].asstring;
      MyReport[i,2]:= SQLQuery1.Fields[2].asstring;
      MyReport[i,3]:= SQLQuery1.Fields[3].asstring;
      MyReport[i,4]:= SQLQuery1.Fields[4].asstring;
      MyReport[i,5]:= SQLQuery1.Fields[5].asstring;
      MyReport[i,6]:= SQLQuery1.Fields[6].asstring;
      MyReport[i,7]:= SQLQuery1.Fields[7].asstring;
      MyReport[i,8]:= SQLQuery1.Fields[8].asstring;
      MyReport[i,9]:= SQLQuery1.Fields[9].asstring;
      MyReport[i,10]:= SQLQuery1.Fields[10].asstring;
      MyReport[i,11]:= SQLQuery1.Fields[11].asstring;
      MyReport[i,12]:= SQLQuery1.Fields[12].asstring;
      i:= i + 1;
      SQLQuery1.Next;
      end;
Memo1.Lines.Clear;
temp := MyReport[0,0];
showmessage ( temp);               

If you have an idea, I will be pleased to hear it!  :o

Best Regards
Jean-Christophe
« Last Edit: September 01, 2014, 11:29:33 am by jeanchristophe »

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: What did I gorget in my array of array?
« Reply #1 on: September 01, 2014, 11:08:42 am »
I think it is because, I have forgot to change the status of SQLQuery.Active from false to true, but when I try to do that, I have the following message:
Code: [Select]
exception class 'External: SIGSEGV' At adress 403E21

Code: [Select]
00403E21 833a00                   cmpl   $0x0,(%edx)

Now I am lost!  :o

Best Regards
Jean-Christophe

Laksen

  • Hero Member
  • *****
  • Posts: 724
    • J-Software
Re: What did I gorget in my array of array?
« Reply #2 on: September 01, 2014, 11:21:34 am »
You set the length of the second dimension to 12, but you you write 13 elements to each row.
So
SetLength(MyReport,count,12);
should be
SetLength(MyReport,count,13);

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: What did I gorget in my array of array?
« Reply #3 on: September 01, 2014, 11:29:16 am »
That was it!
Thank you Laksen to learn me to count to 13!  :D

Best Regards
Jean-Christophe

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [Solved] What did I gorget in my array of array?
« Reply #4 on: September 01, 2014, 11:33:56 am »
Activate range checking. It works for any kind of arrays.

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: [Solved] What did I gorget in my array of array?
« Reply #5 on: September 01, 2014, 12:18:31 pm »
OK thanks Leledumbo!

 

TinyPortal © 2005-2018