RAD Studio VCL Reference
|
Returns the number of items in the collection.
property Count: Integer;
__property int Count;
Count contains the number of items in the Items array. Since Items is indexed starting with 0, the value of Count is always one greater than the index of the last member of Items.
C++ Examples:
/* The following example adds a panel to the status bar control when the user clicks the button and adds a caption to the panel. The code uses BeginUpdate and EndUpdate to prevent repaints until the operation is complete. A try...finally block ensures EndUpdate is called even when an exception occurs. */ void __fastcall TForm1::Button1Click(TObject *Sender) { int PanelIndex; StatusBar1->Panels->BeginUpdate(); PanelIndex = StatusBar1->Panels->Count - 1; try { StatusBar1->Panels->Add(); PanelIndex++; StatusBar1->Panels->Items[PanelIndex]->Text = "Panel" + IntToStr(PanelIndex); } __finally { StatusBar1->Panels->EndUpdate(); } }
/* This example uses the IndexName property to sort the records in a client dataset on the Field2 field. */ void __fastcall TForm1::Button3Click(TObject *Sender) { // If Active is True, Update will remove Fields added in FormCreate // and add the DEFAULT_ORDER and CHANGEINDEX Fields CDS2->Active = False; // Get the current available indices CDS2->IndexDefs->Update(); // Find a field named "Field2" for (int I = 0; I < CDS2->IndexDefs->Count; I++) if (CDS2->IndexDefs->Items[I]->Fields == "Field2") { // set that index as the current index for the dataset} CDS2->IndexName = CDS2->IndexDefs->Items[I]->Name; } CDS2->Active = True; }
/* This example requires a TClientDataSet and a button on a form. */ void __fastcall TForm1::Button1Click(TObject *Sender) { for (int I = 0; I < CDS->Params->Count; I++) { if (CDS->Params->Items[I]->IsNull && CDS->Params->Items[I]->DataType == ftInteger) CDS->Params->Items[I]->AsInteger = -1; }} void __fastcall TForm1::FormCreate(TObject *Sender) { CDS->LoadFromFile(GetCurrentDir() + L"/../CDS.XML"); CDS->Params->CreateParam(ftInteger, "StateParam", ptInput); CDS->Params->CreateParam(ftInteger, "MyParam", ptInput); }
Delphi Examples:
{ The following example adds a panel to the status bar control when the user clicks the button and adds a caption to the panel. The code uses BeginUpdate and EndUpdate to prevent repaints until the operation is complete. A try...finally block ensures EndUpdate is called even when an exception occurs. } procedure TForm1.Button1Click(Sender: TObject); var PanelIndex : Integer; begin with StatusBar1 do begin Panels.BeginUpdate; PanelIndex := StatusBar1.Panels.Count - 1; try Panels.Add; Inc(PanelIndex); Panels.Items[PanelIndex].Text := 'Panel' + IntToStr(PanelIndex); finally Panels.EndUpdate; end; end; end;
{ This example uses the IndexName property to sort the records in a client dataset on the Field2 field. } procedure TForm1.Button3Click(Sender: TObject); var I : Integer; begin // If Active is True, Update will remove Fields added in FormCreate // and add the DEFAULT_ORDER and CHANGEINDEX Fields CDS2.Active := False; { Get the current available indices } CDS2.IndexDefs.Update; { Find a field named 'Field2' } for I := 0 to CDS2.IndexDefs.Count - 1 do if CDS2.IndexDefs.Items[I].Fields = 'Field2' then begin { set that index as the current index for the dataset} CDS2.IndexName := CDS2.IndexDefs.Items[I].Name; end; CDS2.Active := True; end;
{ This example requires a TClientDataSet and a button on a form. } {$IFNDEF UNICODE} uses SwSystem; {$ENDIF} procedure TForm1.Button1Click(Sender: TObject); var I : Integer; begin { Assign -1 to any integer parameter which does not have a value. } for I := 0 to CDS.Params.Count - 1 do if (CDS.Params.Items[I].IsNull) and (CDS.Params.Items[I].DataType = ftInteger) then { Items is the default property, so you can omit its name } CDS.Params[I].AsInteger := -1; end; procedure TForm1.FormCreate(Sender: TObject); begin {$IFDEF UNICODE} CDS.LoadFromFile(GetCurrentDir + '\CDS.XML'); {$ELSE} CDS.LoadFromFile(gsAppPath + 'CDS.XML'); {$ENDIF} CDS.Params.CreateParam(ftInteger, 'StateParam', ptInput); CDS.Params.CreateParam(ftInteger, 'MyParam', ptInput); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|