Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use default Array Properties Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
18-Sep-03
Category
Algorithm
Language
Delphi 2.x
Views
170
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jeff Guidotti

By using default array properties, you can abbreviate your calls by using the 
syntax Class[I] as opposed to Class.Items[I].

Answer:

Delphi supports abbreviated calls to the default class array property.  This can be 
used in any delphi class that uses defaults such as TStringList. 

For Example: 

use MyStringList[Index] in place of MyStringList.Strings[Index]

This is somewhat useful for cleaning up the code, especially if you are accessing 
the property in question often. 

To add this feature to your own classes, simply add the "default" directive 
(storage specifier) after the array (indexed) property you want to use as the 
default. 

For Example: 

1   type
2     TMyGraphicList = class
3     public
4       property Names[Index: Integer]: string read GetName write SetName;
5       property Objects[Index: Integer]: TObject read GetObj write SetObj;
6       property Images[Index: Integer]: TImage read Get write set; default;
7       {...}
8     end;


By adding the "default" directive after the Images property we have designated the 
Images array property as the default.   

Access can now be abbreviated such as this: 

9   for I := 0 to MyGraphicList.Count - 1 do
10  begin
11    AName := MyGraphicList.Names[I];
12    AObject := MyGraphicList.Objects[I];
13    AImage := MyGraphicList[I]; // instead of MyGraphicList.Images[I]
14  end;


NOTE: There can be only one default array property for each class.  Entering a 
second would generate a compiler error. 

IMPORTANT: "Array" properties are different than "attribute" properties, and the default directive takes on a different meaning for each.  When used on an attribute property, the default directive (storage specifier) releates to how Delphi saves the values of published properties in form (.DFM) files.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC