RAD Studio VCL Reference
|
Enables the TStrings object to keep track of when the list of strings has finished changing.
procedure EndUpdate;
__fastcall EndUpdate();
EndUpdate is called automatically by any property or method that changes the list of strings. Call BeginUpdate before directly modifying the strings in the list, and EndUpdate after. When implementing properties or methods that change the list in descendants of TStrings, call BeginUpdate before the changes are made, and EndUpdate when the changes are complete.
TStrings simply keeps track of when the list of strings is being changed. Some descendants of TStrings use this information to perform certain actions, such as telling a control to repaint, when updates are complete.
C++ Examples:
/* This example fills the list of a combo box with the set of open forms when the user drops down the list. The list is regenerated every time the list is dropped down, so if the application opens or closes forms, the combo box stays current. */ #include "Unit2.h" #include "Unit3.h" void __fastcall TForm1::ComboBox1DropDown(TObject *Sender) { ComboBox1->Items->BeginUpdate(); // prevent repaints until done ComboBox1->Items->Clear(); // empty the list of any old values for (int i = 0; i < Screen->CustomFormCount; i++) { if ((reinterpret_cast<TForm1 *>(Screen->CustomForms[i]))->Visible) ComboBox1->Items->Add(Screen->CustomForms[i]->Caption); // add form names } ComboBox1->Items->EndUpdate(); //reenable painting } void __fastcall TForm1::FormCreate(TObject *Sender) { ComboBox1->Sorted = True; // make sure the form names are sorted } void __fastcall TForm1::Button1Click(TObject *Sender) { Form2->Show(); } void __fastcall TForm1::Button2Click(TObject *Sender) { Form3->Show(); }
/* This example requires that a memo and a TApplicationEvent be added to the form. Change the Windows Locale by using the Regional and Language Options in the Windows Control Panel. */ void __fastcall TForm1::ApplicationEvents1SettingChange(TObject *Sender, int Flag, const AnsiString Section, int &Result) { Memo1->Lines->BeginUpdate(); try { // char buffer[64]; AnsiString buffer; buffer.sprintf("Section = %s", Section.c_str()); Memo1->Lines->Add(buffer); buffer.sprintf("Flag = %8x", Flag); Memo1->Lines->Add(buffer); if (strcmp(Section.c_str(), "intl") == 0) { buffer.sprintf("DefaultLCID = %8x", SysLocale.DefaultLCID); Memo1->Lines->Add(buffer); buffer.sprintf("PriLangID = %8x", SysLocale.PriLangID); Memo1->Lines->Add(buffer); buffer.sprintf("SubLangID = %8x", SysLocale.SubLangID); Memo1->Lines->Add(buffer); buffer.sprintf("FarEast = %s", BoolToStr(SysLocale.FarEast, true)); Memo1->Lines->Add(buffer); buffer.sprintf("MiddleEast = %s", BoolToStr(SysLocale.MiddleEast, true)); Memo1->Lines->Add(buffer); Memo1->Lines->Add(""); } } __finally { Memo1->Lines->EndUpdate(); } }
Delphi Examples:
{ This example fills the list of a combo box with the set of open forms when the user drops down the list. The list is regenerated every time the list is dropped down, so if the application opens or closes forms, the combo box stays current. } procedure TForm1.ComboBox1DropDown(Sender: TObject); var I: Integer; begin with ComboBox1 do begin Items.BeginUpdate; { prevent repaints until done } Items.Clear; { empty the list of any old values } for I := 0 to Screen.CustomFormCount - 1 do begin if (Screen.CustomForms[I].Visible) then Items.Add(Screen.CustomForms[I].Caption); { add form name } end; Items.EndUpdate; {reenable painting } end; end; procedure TForm1.FormCreate(Sender: TObject); begin ComboBox1.Sorted := True; { make sure the form names are sorted } end; procedure TForm1.Button1Click(Sender: TObject); begin Form2.Show; end; procedure TForm1.Button2Click(Sender: TObject); begin Form3.Show; end;
{ This example requires that a memo and a TApplicationEvent be added to the form. Change the Windows Locale by using the Regional and Language Options in the Windows Control Panel. } procedure TForm1.ApplicationEvents1SettingChange(Sender: TObject; Flag: Integer; const Section: string; var Result: Integer); begin Memo1.Lines.BeginUpdate; try Memo1.Lines.Add(Format('Section = %s', [Section])); Memo1.Lines.Add(Format('Flags = %.8x', [Flag])); if AnsiSameStr(Section, 'intl') then with SysLocale do begin Memo1.Lines.Add(Format('DefaultLCID = %.8x', [DefaultLCID])); Memo1.Lines.Add(Format('PriLangID = %.8x', [PriLangID])); Memo1.Lines.Add(Format('SubLangID = %.8x', [SubLangID])); Memo1.Lines.Add(Format('FarEast = %s', [BoolToStr(FarEast, True)])); Memo1.Lines.Add(Format('MiddleEast = %s', [BoolToStr(MiddleEast, True)])); end; Memo1.Lines.Add(''); finally Memo1.Lines.EndUpdate; end; // Result:= 0; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|