If your source code include references to arrays, it maybe better to refer to items in those arrays using pre-defined constant variable names rather than plain old numbers. Let's take the following code for example, which basically sets up fields of a database table:
Fields[ 0 ].AsString := 'Joe Blow';
Fields[ 1 ].AsInteger := 25;
Fields[ 3 ].AsString := 'Hiking';
Fields[ 1 ].AsInteger := 25;
Fields[ 3 ].AsString := 'Hiking';
Listing #1 : Delphi code. Download initaray (0.2 KB).
const
// TC = Table Clients (clients.dbf) for example
TC_FULLNAME = 0;
TC_AGE = 1;
TC_HOBBIES = 3;
// ... other code ...
Fields[ TC_FULLNAME ].AsString := 'Joe Blow';
Fields[ TC_AGE ].AsInteger := 25;
Fields[ TC_HOBBIES ].AsString := 'Hiking';
// TC = Table Clients (clients.dbf) for example
TC_FULLNAME = 0;
TC_AGE = 1;
TC_HOBBIES = 3;
// ... other code ...
Fields[ TC_FULLNAME ].AsString := 'Joe Blow';
Fields[ TC_AGE ].AsInteger := 25;
Fields[ TC_HOBBIES ].AsString := 'Hiking';
Listing #2 : Delphi code. Download cnstaray (0.31 KB).
0 comments:
Post a Comment