Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TCatCaseLabel = record
- name: string;
- id: integer;
- end;
- function CatCaseOf(const s: string; labels: array of TCatCaseLabel;
- const casesensitive: Boolean = true): integer;
- var
- i: integer;
- begin
- result := -1; // label not found
- for i := 0 to high(labels) do
- begin
- if casesensitive then
- begin
- if s = labels[i].name then
- result := labels[i].id;
- end
- else
- begin
- if lowercase(s) = lowercase(labels[i].name) then
- result := labels[i].id;
- end;
- if result <> -1 then
- break;
- end;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- const
- ana = 1;
- roberto = 2;
- lucia = 3;
- const
- labels : array [1..3] of TCatCaseLabel =
- (
- (name:'ana';id:ana),
- (name:'roberto';id:roberto),
- (name:'lucia';id:lucia)
- );
- begin
- case CatCaseOf(edit1.text,labels) of
- ana: form1.caption:='ana!';
- roberto: form1.caption:='roberto!';
- lucia: form1.caption:='lucia!';
- else
- form1.Caption:=edit1.text+' not in case list!';
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement