Solved

Using Variant Arrays

Posted on 1997-10-29
3
197 Views
Last Modified: 2010-04-04
My question is this. I am using the type variant in a program I am writing. Now I created an array using
varArrayCreate and I will put some sample sode below. Now it is easy to read data into the variant array except when you get to the last record to read in and I keep getting list index out of bounds. Now I have tried a few different things to try and stop giving me this error. For example, if I made
the following array
tempArray := varArrayCreate([1,10],varVariant) I tried to
read in only up to tempArray[9] and still get list index is out of bounds. Now this is imossible since I am not at the end of the array. Very strange and if anyone can shed some light on this let me know. I must to doing some damn simple
the wrong way. I had a full head of hair before this problem came up. Cheers.

If (Table2.Findkey([TempJobNo]) = false) then
begin
  TotalFields := Table1.FieldCount ;
  TempArray := varArrayCreate([0,TotalFields-1],varVariant);
    For i := 0 to TotalFields-1 do
    begin
      TempArray[i] := Table1.Fields[i].AsVariant ;
      Table1.Next ;
      TempJobNo := Table1.Fieldbyname('JOB_NO').AsString ;
    end
    else
    begin
      Table1.Next ;
      TempJobNo := Table1.Fieldbyname('JOB_NO').AsString ;
    end;
  end;

 {THANKS IN ADVANCE ANYONE}
0
Comment
Question by:westy100697
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 40 total points
ID: 1349171
Westy,

Your right, sometimes it does help to have another programmer look over your code (works for me!). Anyway your problem is in the Table1.FieldCount loop, it SHOULD be:

TotalFields := Table1.FieldCount-1 ;
TempArray := varArrayCreate([0,TotalFields],varVariant);
For i := 0 to TotalFields do
begin
TempArray[i] := Table1.Fields[i].AsVariant ;

The Array is going out of bounds because of the Fields[i] reference.

Good luck with your project!
Pegasus
0
 

Author Comment

by:westy100697
ID: 1349172
Hey thanks for the help but solved the problem by going away and having a cuppa and it came to me all of a sudden. Happens a lot when you relax for while and come back to it. Will give you the points though cause it is exactly the prob. Thanks muchly !
0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349173
Glad to be of help Westy!

You'll have to reject or accept the answer before the Expert Exchange system will clear it from the list of QX's awaiting answers.

Regards
Pegasus
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

20 Experts available now in Live!

Get 1:1 Help Now