Advertisement
zoltanleo

Untitled

Nov 3rd, 2022
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.36 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, StdCtrls, SysUtils, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     ComboBox1: TComboBox;
  16.     Label1: TLabel;
  17.     procedure ComboBox1Change(Sender: TObject);
  18.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  19.     procedure FormCreate(Sender: TObject);
  20.   private
  21.     FStrList: TStringList;
  22.     procedure SetStrList(AValue: TStringList);
  23.  
  24.   public
  25.     property StrList: TStringList read FStrList write SetStrList;
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1.FormCreate(Sender: TObject);
  38. var
  39.   i: PtrInt = 0;
  40. begin
  41.   FStrList:= TStringList.Create;
  42.  
  43.   for i:= 0 to 9 do
  44.     StrList.AddObject(Format('string_%d (added as Object: %d)',[Succ(i),i]),TObject(i));
  45.  
  46.   ComboBox1.Items.Assign(StrList);
  47.   ComboBox1.ItemIndex:= 0;
  48.   ComboBox1Change(Sender);
  49. end;
  50.  
  51. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  52. begin
  53.   FreeAndNil(FStrList);
  54. end;
  55.  
  56. procedure TForm1.ComboBox1Change(Sender: TObject);
  57. begin
  58.   Label1.Caption:= 'PtrInt(Object): ' + IntToStr(PtrInt(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
  59. end;
  60.  
  61. procedure TForm1.SetStrList(AValue: TStringList);
  62. begin
  63.   if StrList.Equals(AValue) then Exit;
  64.   FStrList.Assign(AValue);
  65. end;
  66.  
  67. end.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement