![]() |
|
case of with string - نسخة قابلة للطباعة +- delphi4arab منتديات دلفي للعرب (https://delphi4arab.net/forum) +-- قسم : متتديات باسكال Pascal (https://delphi4arab.net/forum/forumdisplay.php?fid=7) +--- قسم : Lazarus - Free Pascal - CrossKylix - Kylix - CrossVCL (https://delphi4arab.net/forum/forumdisplay.php?fid=34) +--- الموضوع : case of with string (/showthread.php?tid=9152) |
case of with string - mobile - 31-01-2018 السلام عليكم ورحمة الله في Lazarus fpc 2.6.0 كود : procedure TForm1.Button1Click(Sender: TObject);
begin
case edit1.Text of
'one': caption := 'one';
'111': caption := '1';
end;
end;كود : function CaseOfString(s: string; a: array of string): Integer;
begin
Result := 0;
while (Result < Length(a)) and (a[Result] <> s) do
Inc(Result);
if a[Result] <> s then
Result := -1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
case CaseOfString(Edit1.Text, ['42', '23', 'nerd alert', 'hello world']) of
0: Label1.Caption := 'What is ?';
1: Label1.Caption := 'Tow';
2: Label1.Caption := 'yes';
3: Label1.Caption := 'Hello';
else
Label1.Caption := '?';
end;
end; |