User: alciro    User
 Original    Translate to:  Deutsch  English  Français  中文  
 

Programación en C++ Builder

 Arrays (arrays)
 Pointers
3. Example of class in c + +
8. AnsiString class methods
 C + + projects
 Packages, distribute an application without installation
 Exchange or bubble sorting
 String string.h functions

5. Files. INI

Description

5.1. Properties and methods AnsiString class

Count
Number of channels in the list.

Introduce an abstract property to Represent the number of strings in the list.

 __property int Count = {read = getCount, NODEFAULT}; 

Description

Descendants of TStrings implemented Count property to Indicate the number of strings in the list.

Use the Count property When iterating over all the strings in the list, or when to Trying to locate the position of a string relative to the last string in the list.

Names
Variable name.

Indicates the name part of strings with the form Name = Value.

 __property AnsiString Names [int Index] = {read = GetName}; 

Description

When the list of strings for the TStrings object includes strings of the form Name = Value, read Names to access the name part of a string. Names is the name part of the string at the position Indicated by Index. Index Gives the position of the string, where, 0 is the first string, 1 is the second string, and so on. If the string at the Specified position not is of the form Name = Value, Names returns an empty string.

Strings of the form Name = Value Are Commonly found in. Ini files. For example, Here Are A Few strings taken from a typical. Ini file:


Displaygrid = 1
SnapToGrid = 1
GridSizeX = 8
GridSizeY = 8

The Name that the string identifier is to the left of the equal sign (=), and the current Value of the Name identifier is on the right side. There Should Be no spaces present Before or after the equal sign.

Values
Value of the variable.

Represents the value part of a string associated with a Given Name, on strings with the form Name = Value.

 __property AnsiString Values [AnsiString Name] = {read = GetValue, SetValue write =}; 

Description

When the list of strings for the TStrings object includes strings of the form Name = Value, Values use or September to get the value part of a string name associated with a specific part. If the list not does contain any strings of the Proper Name = Value form, or if none of Those strings matches the Name index, returns an empty string Values.

Note: The name index is case-insensitive. That is, Values is the value part for the first Occurrence of Name or an equivalent string That differs only in case.

Strings of the form Name = Value Are Commonly found in. Ini files. For example, Here Are A Few strings taken from a typical. Ini file:


Displaygrid = 1
SnapToGrid = 1
GridSizeX = 8
GridSizeY = 8

The Name that the string identifier is to the left of the equal sign (=), and the current Value of the Name identifier is on the right side. There Should Be no spaces present Before or after the equal sign.

IndexOfName
Index variable.

Returns the position of the first string with the form Name = Value with the name specified part.

 virtual int __fastcall IndexOfName (const AnsiString Name); 

Description

Call IndexOfName to locate the first Occurrence of a string with the form Name = Value Where the name part is equal to the Name parameter or only differs in case. IndexOfName returns the 0-based index of the string. If no string in the Indicated list has the name, IndexOfName returns -1.

Strings of the form Name = Value Are Commonly found in. Ini files. For example, Here Are A Few strings taken from a typical. Ini file:


Displaygrid = 1
SnapToGrid = 1
GridSizeX = 8
GridSizeY = 8

The Name that the string identifier is to the left of the equal sign (=), and the current Value of the Name identifier is on the right side. There Should Be no spaces present Before or after the equal sign.

Note: If There Is More Than One Portion string with a name matching the name parameter, IndexOfName returns the position of the first Such string.

5.2. Example of use

If you have a text box named Memo1 that contains the data shown in the following table, we can access the values or variable names by using the properties Names, Values .

Index Memo1 Content
0 Variable1 = 1
1 Variable2 = 8
2 Variable3 = 10

 int Pos, Ind;
String name, Dato;
Pos = Memo1-> Lines-> Count () / / Returns the maximum rate of the lines (2)
Name = Memo1-> Lines-> Names [1] / / Returns the name of the variable (variable2)
Ind = Memo1-> Lines-> IndexOfName (Variable3 ") / / Returns the index of the variable (2)
M = Memo1-> Lines-> Values ["variable2"] / / returns the value of the variable (8)
Memo1-> Lines-> Values ["variable2"] = 134, / / Assign the value 134 to variable 2
/ / If there creates the string "variable2 = 134" and appended to the list 

5.2.1. Setting environment variables

Insert a secret memo (with the property Visible = false)

Saving Variables

 Memo2->Lines->Values["Top"]=Form1->Top; 
Memo2->Lines->Values["Left"]=Form1->Left;
Memo2->Lines->Values["Width"]=Form1->Width;
Memo2->Lines->Values["Heigth"]=Form1->Heigth;
Memo2->Lines->Values["Color"]=Form1->Color;
Memo2->Lines->Values["DrTrabajo"]=OpenDialog1->FileName;

To save, use SaveDialog1-> FileName

Retrieve Variables

 OpenDialog->InitialDir=Memo2->Lines->Values["DrTrabajo"]; 
Form1->Top=Memo2->Lines->Values["Top"].ToInt();
Memo1->Color=Memo2->Lines->Values["Color"].ToInt()

Save the configuration file (when you close the application,

 Memo2->Lines->SaveToFile("Config.cfg"); 

Retrieve the configuration file (when you open the application, OnCreate or constructor)

 Memo2->Lines->LoadFromFile("Config.cfg"); 
Loading
copyright © 2007-2024  www.alciro.org  All rights reserved.         
Share |