Chapter III-List of strings and Applications (ii) (1)

Source: Internet
Author: User

3.1.4 Add objects to the list of strings

The list of strings can store objects in the Objects property in addition to storing strings in the strings property. Like stings, objects can also be indexed, which is the index of an object.

The use of strings in the application list does not have much to do with whether there are objects in the list. Unless the program specifically accesses the object, the contents of the objects are unchanged, and Delphi simply saves the information and the application operates on it if necessary.

Some string lists ignore the objects that are joined. The list of rows represented in the TMemo part is not saved to the object in which it is added. There are also a list of strings that relate objects to strings, such as the Pages property of the Tnotebook part, which holds both the name of the page and the object representing the page. If the application adds or deletes a string to pages, Delphi automatically adds or deletes the corresponding object.

Although programs can assign any type of object to a list, the most common is to associate bitmaps with strings in a custom-drawn control, noting that bitmaps and strings are used in pairs.

Delphi does not break the corresponding string when releasing the memory space of the object.

3.1.4.1 an object in the list of action strings

For each action method of a string, the objects in the list have a corresponding method. For example, an application can use an object's index to access an object. Unlike strings, objects cannot be omitted because strings is the lack of a list.

Table 3.1 summarizes the methods that strings manipulate strings and objects.

Table 3.1 tstrings methods for string properties and object manipulation properties

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Manipulating String objects

───────────────────────────────

Accessing the Strings Property objects Properties

Add Item Add Method Addobjects method

Inserts the item Insert method Insertobjects method

Indexofobject method of Project location IndexOf method

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Delete,clear,more the entire project, that is, deleting the string and deleting the corresponding object. However, the Loadfromfile,savetofile method only operates on strings.

3.1.4.2 Join Object

If you associate an object with an existing string, Delphi assigns the same index number to the object. For example, a list called fruits has a string (' Apple ') that allows a program to associate a bitmap named Applebitmap with an apple character.

With the Fruits do Objects[indexof (' Apple ')]:=applebitmap;

Another method is to invoke the AddObject method of the list, AddObject has two parameters: strings and objects, as follows:

Fruits addobject (' Apple ', applebitmap);

3.2 String List application

The Delphi application often uses a list of strings that we write strlist. DPR is a simple program that applies a list of strings. The program runs as shown in Figure 3.2. The list box lists the various font names supported by the screen and appears in the list in the font represented by the name; The tabs label is not just a string, but a bitmap. This is called the self-painting control. The following is an introduction to the application of the string list in self-painting control.

The list box, combo box, and Tabset part has a style called "OwnerDraw", which replaces the text output of Windows, and the part's self painting control is redrawn for each item in its run state. The most common is to use images instead of text output.

A common feature of self-painting controls is that they all contain a list of items, which by default are lists of strings that Windows displays as text. Delphi can associate a list of strings with an object, which allows the application to draw projects with objects.

Typically, there are three steps to creating a custom-drawn control:

1. Set self painting style;

2. Add image objects to the list of strings;

3. Draw a self painting project.

3.2.1 Set self painting style

Each part that can be controlled by itself has a property called style, which determines whether the part draws the item by default or in a custom way.

There are also custom style options for list boxes and combo boxes, and table 3.2 lists the values and meanings of style.

Table 3.2 Style's value and meaning

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Example of Style meaning

─────────────────────────────────

Fixed each item has the same height of 1bOwnerDrawFixed

Height is determined by the Itenheight property csownerdrawfixed

Varible each item has a different height of 1bOwnweDrawVarible

Determined by the running data csownerdrawvarible

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The style property of Tab-set and string grids is usually varible.

In the Strlist program, the list box and Tab-set are evaluated as Table 3.3:

Table 3.3 Values for list boxes and Tab-set

━━━━━━━━━━━━━━━━━━━━━━━━━━

Name Style

──────────────────────────

ListBox1 lbownerdrawvariable

Tabset1 tsownerdrawvariable

━━━━━━━━━━━━━━━━━━━━━━━━━━━

3.2.2 the image into a string list

The previous section describes how to add objects to a list of strings, and routines add bitmap objects to the Tabset1 tabs:

Procedure Tform1.formcreate (Sender:tobject);

Var

Bitmap:tbitmap;

Begin

Listbox1.items: = screen.fonts;

Bitmap: = tbitmap.create;

Bitmap.loadfromfile (' PHONE. BMP ');

Tabset1.Tabs.AddObject (' phone ', Bitmap);

Bitmap: = tbitmap.create;

Bitmap.loadfromfile (' PRINTER. BMP ');

Tabset1.Tabs.AddObject (' printer ', Bitmap);

End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.