delphi4arab منتديات دلفي للعرب
كيف اختار رقمين من قائمة مكون listbox أو combobox - نسخة قابلة للطباعة

+- delphi4arab منتديات دلفي للعرب (https://delphi4arab.net/forum)
+-- قسم : منتديات دلفي للعرب التعليمية (https://delphi4arab.net/forum/forumdisplay.php?fid=3)
+--- قسم : سؤال و جواب حول دلفي (https://delphi4arab.net/forum/forumdisplay.php?fid=15)
+--- الموضوع : كيف اختار رقمين من قائمة مكون listbox أو combobox (/showthread.php?tid=10955)



كيف اختار رقمين من قائمة مكون listbox أو combobox - theghost - 13-07-2020

السلام عليكم و رحمة الله و بركاته

عندي قائمة listbox أو combobox فيها الأعداد التالية 
100 110 120 130 150 160 180 200 220 240 270 300 330 360 390 430 470 510 560 620 680 750 820 910
عندما أجري عملية البحث من المكون edit1  مثال العدد 350 ليس في القائمة أريد أن يعطيني الرقمين 330 و 360 لم أجد الحل


RE: كيف اختار رقمين من قائمة مكون listbox أو combobox - ghostdz - 13-07-2020

جرب الكود التالي

كود :
function SearchValue(List: TStrings; Value: string; out Value1, Value2: string): Boolean; var   I: Integer; begin   Result := False;   for I := 0 to List.Count - 1 do     if StrToInt(Trim(List.Strings[I])) >= StrToInt(Trim(Value)) then     begin       Result := (StrToInt(Trim(List.Strings[I])) = StrToInt(Trim(Value)));       Break;     end;   if Result then   begin     Value1 := Value;     Value2 := Value;   end   else   begin     if I > 0 then       Value1 := List.Strings[I - 1];     if I < List.Count then       Value2 := List.Strings[I];   end; end;

يتم إستخدام الدالة كالتالي
كود :
procedure TForm2.Button1Click(Sender: TObject); var   Value1, Value2: string; begin   if SearchValue(ListBox1.Items, Edit1.Text, Value1, Value2) then     ShowMessage('Value found')   else ShowMessage('Value not found, ' +Value1 + ' - ' + Value2); end;



RE: كيف اختار رقمين من قائمة مكون listbox أو combobox - theghost - 13-07-2020

شكرا أخي الكود يعمل جبدا شكرا جزيلا