shidqul

u_combobox_sidecool

Sep 4th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.47 KB | None | 0 0
  1. unit u_combobox_sidecool;
  2.  
  3. interface
  4.  
  5. uses
  6.   StdCtrls;
  7.  
  8. type
  9.   TString_ = class(TObject)
  10.   private
  11.    FStr: String;
  12.   public
  13.    constructor Create(const AStr: String);
  14.   property
  15.    Str: String read FStr write FStr;
  16.   end;
  17.  
  18.   procedure AddItemComboBox(ComboBoxName: TCustomComboBox; Value: String; Key: String);
  19.   function getComboBoxIndex(ComboBoxName: TCustomComboBox; Key: String): Integer;
  20.   function getComboBoxKode(ComboBoxName: TCustomComboBox): String;
  21.   function getComboBoxText(ComboBoxName: TCustomComboBox): String;
  22.  
  23. implementation
  24.  
  25. { TString_ }
  26.  
  27. constructor TString_.Create(const AStr: String);
  28. begin
  29.  inherited Create;
  30.  FStr := AStr;
  31. end;
  32.  
  33. procedure AddItemComboBox(ComboBoxName: TCustomComboBox; Value,
  34.   Key: String);
  35. begin
  36.  ComboBoxName.Items.AddObject(Value, TString_.Create(Key));
  37. end;
  38.  
  39. function getComboBoxIndex(ComboBoxName: TCustomComboBox;
  40.   Key: String): Integer;
  41. var
  42.  i: Integer;
  43. begin
  44.  i := 0;
  45.  while i < ComboBoxName.Items.Count do
  46.   begin
  47.    if TString_(ComboBoxName.Items.Objects[i]).Str = Key then
  48.     begin
  49.      Result := i;
  50.     end;
  51.    i := i+1;
  52.   end;
  53. end;
  54.  
  55. function getComboBoxKode(ComboBoxName: TCustomComboBox): String;
  56. begin
  57.  if ComboBoxName.ItemIndex >= 0 then
  58.   Result := TString_(ComboBoxName.Items.Objects[ComboBoxName.ItemIndex]).Str;
  59. end;
  60.  
  61. function getComboBoxText(ComboBoxName: TCustomComboBox): String;
  62. begin
  63.  if ComboBoxName.ItemIndex >= 0 then
  64.   Result := TComboBox(ComboBoxName).Text;
  65. end;
  66.  
  67. end.
Advertisement
Add Comment
Please, Sign In to add comment