Collections |
Top Previous Next |
DFM-Translator > Special assignments > Collections Another special kind of assignments are collections. Their values are listed as items in angle brackets "<" ... ">". Each item consists of a series of assignments within an item structure that begins with the keyword item and ends with the keyword end. For example, a status bar consists of such items
object StatusBar1: TStatusBar ... Panels = < item Width = 150 end item Width = 50 end> end
By default, this example is translated as follows:
StatusBar1 = new TStatusBar(this); ... StatusBar1->Panels->Add(); StatusBar1->Panels->Items[0]->Width = 150; StatusBar1->Panels->Add(); StatusBar1->Panels->Items[1]->Width = 50;
However, not all collection classes have an Add-member function. For example TFieldDefs, which is used in a TClientDataSet doesn't have this method. It has the member AddFieldDef instead. For such cases special assignments can be defined again. By user of the type TFieldDef and the name part item a function can be defined, by which the following code can be translated:
Object ClientDataSet1: TClientDataSet ... FieldDefs = < Item Name = 'Species No' DataType = ftFloat end Item Name = 'Category' DataType = ftString Size = 15 end
The translated code then is:
ClientDataSet1 = new TClientDataSet(this); ... GetTFieldDefsitem(ClientDataSet1->FieldDefs, 0)->Name = L"Species No"; GetTFieldDefsitem(ClientDataSet1->FieldDefs, 0)->DataType = ftFloat; GetTFieldDefsitem(ClientDataSet1->FieldDefs, 1)->Name = L"Category"; GetTFieldDefsitem(ClientDataSet1->FieldDefs, 1)->DataType = ftString; GetTFieldDefsitem(ClientDataSet1->FieldDefs, 1)->Size = 15;
The function GetTFieldDefsitem will create e new TFielDef if there is no for the current index, otherwise it will return the existing one.
For other compilers then C#Builder the output will be:
ClientDataSet1 = new TClientDataSet(this); ... GetTFieldDefsitem(ClientDataSet1->FieldDefs, 0)->WritePropertyName(L"Species No"); GetTFieldDefsitem(ClientDataSet1->FieldDefs, 0)->WritePropertyDataType(ftFloat); GetTFieldDefsitem(ClientDataSet1->FieldDefs, 1)->WritePropertyName(L"Category"); GetTFieldDefsitem(ClientDataSet1->FieldDefs, 1)->WritePropertyDataType(ftString); GetTFieldDefsitem(ClientDataSet1->FieldDefs, 1)->WritePropertySize(15);
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |