Merhaba,
Dictionary tanımında hata yapmışsınız sanırım. Muhtemelen Key değeri için record kullanmamalısınız. Basit bir değer kullanılır genelde, Integer veya string gibi değerler. Siz TDictionary içinde "Key" erişimi için TKeyRec kullanmışsınız.
Aşağıdaki şekilde tanım yapıp denediğimde Delphi 11.3 ile sorunsuz çalışıyor.
FORM
Kod: Tümünü seç
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 442
ClientWidth = 628
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Segoe UI'
Font.Style = []
OnCreate = FormCreate
TextHeight = 15
object Label1: TLabel
Left = 104
Top = 24
Width = 125
Height = 15
Caption = '1-20 aras'#305' aranan de'#287'er:'
end
object Button1: TButton
Left = 8
Top = 16
Width = 75
Height = 33
Caption = 'Ara'
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 8
Top = 64
Width = 612
Height = 370
Lines.Strings = (
'Memo1')
TabOrder = 1
end
object NumberBox1: TNumberBox
Left = 235
Top = 21
Width = 38
Height = 23
MinValue = 1.000000000000000000
MaxValue = 20.000000000000000000
TabOrder = 2
end
end
Unite
Kod: Tümünü seç
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.NumberBox;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
NumberBox1: TNumberBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
System.Generics.Collections;
type
TKeyKor = record
sno: Integer;
xadi: string;
yadi: string;
end;
var
// Aşağıdaki tanımda "Key" bir tamsayı, karşılığında saklanacak değerler "TKeyKor" türünde
DicKor: TDictionary<Integer, TKeyKor>;
procedure TForm1.Button1Click(Sender: TObject);
var
LKey: TKeyKor;
begin
// Kullanıcının girdiği değer TDictionary içinde aranıyor
// Bulunursa LKey içi saklanan veri ile dolduruluyor
if not DicKor.TryGetValue(NumberBox1.ValueInt, LKey) then
begin
Memo1.Lines.Add('Değer bulunamadı');
end
else
begin
Memo1.Lines.Add('Kayıt bilgileri:');
Memo1.Lines.Add('SNo: ' + LKey.sno.ToString());
Memo1.Lines.Add('xadi: ' + LKey.xadi);
Memo1.Lines.Add('yadi: ' + LKey.yadi);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
LKor: TKeyKor;
I: Integer;
begin
Memo1.Clear();
DicKor := TDictionary<Integer, TKeyKor>.Create();
for I := 1 to 20 do
begin
LKor.sno := I;
LKor.xadi := Chr(64+I);
LKor.yadi := I.ToString();
// Key bilgisi tamsayı "I" değişken değeri ile saklanıyor.
// Saklanacak veri ise LKor içinde oluyor.
DicKor.Add(I, LKor);
end;
end;
end.