1. Home
  2. Computing & Technology
  3. Delphi Programming
RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To
 
Creating Custom Delphi Components, Part II
Page 2: Sets.
 More of this Feature
• Page 1: Component references
• Page 3: Binary properties
• Page 4: Collections
• Page 5: Sub-properties

• Download Demo Projects
 Join the Discussion
"Post your questions, concerns, views and comments to this article..."
Discuss!
 Related Resources
• Custom VCL development
• VCL with source
• Third party VCL
• VCL using

   Sets
This section is really quite simple and will not take long to cover. I do not doubt that you are already familiar with creating your own ordinal types.

type
  TComponentOption = (coDrawLines,
                      coDrawSolid,
                      coDrawBackground);  

Properties of this type will show a combobox with a list of all possible values, but sometimes you will need to set a combination of many (or all) of these values. This is were sets come in to play

Type
  TComponentOption = (coDrawLines,
                      coDrawSolid,
                      coDrawBackground);  
  TComponentOptions = set of TComponentOption;

Publishing a property of type TComponentOptions would result in a [+] appearing next to our property name. When you click to expand the property you will see a list of options. For each element in TComponentOption you will see a Boolean property, you can include / exclude elements from your set by setting its value to True / False.

It is simple to check / alter elements in a set from within our component like so.

if coDrawLines in OurComponentOptions
  then DrawTheLines; 

or

procedure TsomeComponent.SetOurComponentOptions(const value : TComponentOptions);
begin
  if (coDrawSolid in Value) and
  (coDrawBackground in value) then
    {raise an exception}

  FOurComponentOptions := Value;
  Invalidate;
end;

Next page > Binary properties > Page 1, 2, 3, 4, 5

Creating Custom Delphi Components >>
>> Part III.

All graphics (if any) in this feature created by Peter Morris.

 More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Lookup! - DB/15.
Chapter fifteen of the free Delphi Database Course for beginners. See how to use lookup fields in Delphi to achieve faster, better and safer data editing. Also, find how to create a new field for a dataset and discuss some of the key lookup properties. Plus, take a look at how to place a combo box inside a DBGrid.
 Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.