IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...   Print This     
Next Random Article Next Random Tidbit || Change Topic Random From All

Random Tidbit

Part of the mo. lesson in the May 10 Issue of Prestwood eMag
Delphi Code Snippet:
 A flashcard from our Delphi Flashcards Library
 A code snippet from our Delphi Code Snippets Page
 Tags: Delphi , Array
Delphi Array (x=Array[0..3] of string;)

Delphi supports both static and dynamic arrays.


var
  MyArray: array[0..3] of string;
  i: Integer;
begin
  MyArray[0] := 'Mike';
  MyArray[1] := 'Lisa';
  MyArray[2] := 'Felicia';
  MyArray[3] := 'Nathan';
  
  for i := 0 to High(MyArray) do
    ShowMessage(MyArray[i]);
end;
Switch to longer article version of Delphi Array (x=Array[0..3] of string;) (Pascal and Delphi Coding)

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 2

Excellent.

I love arrays. I use them to hold data (array of a record) for data in/out of the application. I use these in lieu of data-aware controls. My options are much greater if I do not use data-aware controls.

Here is how I implement dynamic arrays:

1) declare a record

TrecAddress = record
  Name:   string;
  Address: string;
 City: string;
 State: string;
 Zip: string;
end;

2) my dynamic array defined:

TaryAddressRec = array of TrecAddress;

3) gather some data in a query, then iterate through the query to dimension the array size

var
nCount: integer;
aryWork: TaryAddressRec;
begin
nCount := 0;
while (not qryWork.Eof) do
begin
  inc(nCount);
  qryWork.Next;
end;

// sets the size of the array to the number of rows found
// since I deal with multipe DB types, Access, Oracle, MySQL, Elevate, I cannot rely on recordcount.

SetLength(aryWork,nCount);
nCount := -1;
while (not qryWork.Eof) do
begin
 // may wish to initialize the array record here
 inc(nCount);
 // load the array
 aryWork[nCount].Name := qryWork.FieldByName('Name').AsString;
 aryWork[nCount].Address := qryWork.FieldByName(Address').AsString;
...
qryWork.Next;
end;
// close connection
end;

Anyway, I like arrays - they are Cool

Posted 11 years ago

Comment 2 of 2

A simple array with more explaination is now launched. More information you can check when you start to read assignment help, I also want to invite you to read these array which you can see in the data.

Posted 13 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1172A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Beginner

1 Beginner Level Question

Question #1: Multiple Choice

Which is the correct syntax for declaring an array and setting two values of the array?

Answer:
1. 
var
  MyArray: array[0..3] of string;
begin
  MyArray[0] := 'Mike';
  MyArray[1] := 'Lisa';
end;
2. 
Dim MyArray As Variant
MyArray = Array("Mike", "Lisa")
3. 
var
  MyArray Array[2] String
endVar
MyArray[1] = "Mike"
MyArray[2] = "Lisa"
4. 
var
  MyArray: array[0..3] of string;
begin
  MyArray(0) = 'Mike';
  MyArray(1) = 'Lisa';
end;
5. 
var
  MyArray array(0..3) : string;
begin
  MyArray[0] := 'Mike';
  MyArray[1] := 'Lisa';
end;

 KB Article #102139 Counter
22299
Since 3/30/2010
Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2021 Prestwood IT Solutions.   [Security & Privacy]