Causes the flow of control to exit a for, while, or repeat statement.
procedure Break;
Break();
System
The Break procedure causes the flow of control in Delphi code to exit a for, while, or repeat statement and continue at the next statement following the loop statement.
A call to Break must be contained in a for, while, or repeat statement, or the compiler reports an error.
Delphi Examples:
{ The following OnFind event handler searches a memo component for the text specified in the FindText property of a find dialog component. If found, the first occurrence of the text in Memo1 is selected. The code uses the Pos function to compare strings, and stores the number of characters to skip when determining the selection position in the SkipChars variable. Because there is no handling of case, whole word, or search direction in this algorithm, it is assumed that the Options property of FindDialog1 is set to [frHideMatchCase, frHideWholeWord, frHideUpDown]. } procedure TForm1.FindDialog1Find(Sender: TObject); var I, J, PosReturn, SkipChars: Integer; begin for I := 0 to Memo1.Lines.Count do begin PosReturn := Pos(FindDialog1.FindText,Memo1.Lines[I]); if PosReturn <> 0 then {found!} begin SkipChars := 0; for J := 0 to I - 1 do SkipChars := SkipChars + Length(Memo1.Lines[J]); SkipChars := SkipChars + (I*2); SkipChars := SkipChars + PosReturn - 1; Memo1.SetFocus; Memo1.SelStart := SkipChars; Memo1.SelLength := Length(FindDialog1.FindText); Break; end; end; end; procedure TForm1.FormCreate(Sender: TObject); const Path = 'country.list'; begin Memo1.Lines.LoadFromFile(Path); end;
{ The following example shows how to complete partial strings typed into a combo box. The code represents the OnKeyPress event handler of the combo box, which performs most of the default keystroke handling before finding a matching list item and updating the text. Note: This OnKeyPress event handler does not deal with the case when the user types the Delete key. That case must be caught in the OnKeyDown event handler instead. Note: Set the TComboBox AutoComplete to false to turn off default auto completion. } procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char); var Found: boolean; i, ct, SelSt: Integer; TmpStr: string; begin { first, process the keystroke to obtain the current string } { This code requires all items in list to be uppercase} if Key in ['a'..'z'] then Dec(Key,32); {Force Uppercase only!} ct := (Sender as TComboBox).Items.Count; with (Sender as TComboBox) do begin SelSt := SelStart; if (Key = Chr(vk_Back)) and (SelLength <> 0) then TmpStr := Copy(Text, 1, SelStart) + Copy(Text, SelLength + SelStart + 1, 255) else if Key = Chr(vk_Back) then {SelLength = 0} TmpStr := Copy(Text, 1, SelStart-1) + Copy(Text, SelStart + 1,255) else {Key in ['A'..'Z', etc]} TmpStr := Copy(Text, 1, SelStart) + Key + Copy(Text, SelLength + SelStart + 1, 255); if TmpStr = '' then Exit; { update SelSt to the current insertion point } if (Key = Chr(vk_Back)) and (SelSt > 0) then Dec(SelSt) else if Key <> Chr(vk_Back) then Inc(SelSt); Key := #0; { indicate that key was handled } if SelSt = 0 then begin Text:= ''; Exit; end; {Now that TmpStr is the currently typed string, see if we can locate a match } Found := False; for i := 1 to ct do begin if Copy(Items[i - 1], 1, Length(TmpStr)) = TmpStr then begin Text := Items[i-1]; { update to the match that was found } ItemIndex := i-1; Found := True; Break; end; end; if Found then { select the untyped end of the string } begin SelStart := SelSt; SelLength := Length(Text) - SelSt; end else Beep; end; end; var CharSetList : TStringList; procedure TForm1.AddCharacterSet(const S: string); begin CharSetList.Add(S); end; procedure TForm1.FormCreate(Sender: TObject); begin CharSetList := TStringList.Create; Graphics.GetCharsetValues(AddCharacterSet); ComboBox1.Items := CharSetList; end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|