Value Ozelligi olan ComboBox

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
abdulkadir
Kıdemli Üye
Mesajlar: 489
Kayıt: 13 Eyl 2003 09:10
Konum: istanbul
İletişim:

Value Ozelligi olan ComboBox

Mesaj gönderen abdulkadir »

S.a
items haricinde value özelligi olan bir combobox a ihtiyacınız varsa buyrun

Kod: Tümünü seç

{************************************************************}
{       CodeGear Delphi 2007 Visual Component Library den    }
{       TComboBox Sınıfından olusuturulmuş                   }
{                     Ek olarak                              }
{       Values  ve About özelligi eklenmistir                }
{       Abdulkadir LEVENT   12.05.2009                       }
{************************************************************}
unit MyComboBox;

interface

uses
  SysUtils, Classes, Controls, StdCtrls;

type
  TMyComboBox = class(TComboBox)
  private
    { Private declarations }
    FAbout: String;
    FValues: TStrings;
    procedure SetValues(Value: TStrings);
    function Get_About: string;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Values: TStrings read FValues write SetValues;
    property About: string read Get_About write FAbout stored False;
  end;

procedure Register;

implementation
constructor TMyComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FValues := TStringList.Create;
  Style := csDropDownList;
end;

destructor TMyComboBox.Destroy;
begin
  TStringList(FValues).OnChange := nil;
  FValues.Free;
  inherited Destroy;
end;

procedure TMyComboBox.SetValues(Value: TStrings);
begin
  FValues.Assign(Value);
end;

function TMyComboBox.Get_About: string;
begin
  Result :='Abdulkadir LEVENT';
end;

procedure Register;
begin
//hangi component baslıgı altına kaydedilsin (Tool Palette)
  RegisterComponents('Abdulkadir', [TMyComboBox]);
end;

end.
Bunu delphide nasıl derleyeceginizi bilirsiniz herhalde anlatmaya gerek duymuyorum
forumda bu konu fazlası ile mevcuttur.
iyi calısmalar
Fikirleri Aktar
Kaynakları Dagıt
Ve
Yoldan Çekil
http://www.Leventler.com.tr
abdulkadir
Kıdemli Üye
Mesajlar: 489
Kayıt: 13 Eyl 2003 09:10
Konum: istanbul
İletişim:

Re: combobox items + value özelligi olan

Mesaj gönderen abdulkadir »

Kullanıma örnek yazmadan gecmeyeyim
//MyComboBox componenti yuklenmiş olmalı :)

Kod: Tümünü seç

//form create edilirken MyComboBox1 items ve value degerlerini yukleyelim.
procedure TForm3.FormCreate(Sender: TObject);
begin
 MyComboBox1.Items.Clear;//gecmisi sil
 MyComboBox1.Values.Clear;
 MyComboBox1.Items.Add('Abdulkadir');MyComboBox1.Values.Add('1999');
 MyComboBox1.Items.Add('Ahmet');     MyComboBox1.Values.Add('2006');
 MyComboBox1.Items.Add('Mustafa');   MyComboBox1.Values.Add('1516');
 MyComboBox1.Items.Add('Hüseyin');   MyComboBox1.Values.Add('2345');
 MyComboBox1.Items.Add('Kemal');     MyComboBox1.Values.Add('677809');
 MyComboBox1.Items.Add('Cemal');     MyComboBox1.Values.Add('776543');
 MyComboBox1.Items.Add('Yahya');     MyComboBox1.Values.Add('0987654');
 MyComboBox1.Items.Add('Bulut');     MyComboBox1.Values.Add('0987654');
end;
MyComboBox1 onClick olayına asagıdaki kodu yazalım

Kod: Tümünü seç

procedure TForm3.MyComboBox1Click(Sender: TObject);
var Item,Value:String;
begin
 if MyComboBox1.ItemIndex > -1 then begin

    Item:=MyComboBox1.Items[MyComboBox1.ItemIndex];

    Value:=MyComboBox1.Values[MyComboBox1.ItemIndex];

     ShowMessage('Seçilen Satır:= '+Item +' Value:= '+Value );
 end;
end;
bu satırları yazarken bunu yaptın bari paketi derle bilmeyenler ugrasmasın diye hep gecti içimden
ve derledim zipli dosya linki asagıda

http://rapidshare.com/files/232105402/A ... T.zip.html
Sevgiler....
Fikirleri Aktar
Kaynakları Dagıt
Ve
Yoldan Çekil
http://www.Leventler.com.tr
Kullanıcı avatarı
Battosai
Üye
Mesajlar: 1316
Kayıt: 01 Eki 2007 12:02
Konum: Ankara

Re: combobox items + value özelligi olan

Mesaj gönderen Battosai »

Aslında MyComboBox1.Items.AddX('Abdulkadir','2006'); şeklinde ekleme yapılabilen bir özellik eklerseniz daha şık olurdu bu MyCombobox...
abdulkadir
Kıdemli Üye
Mesajlar: 489
Kayıt: 13 Eyl 2003 09:10
Konum: istanbul
İletişim:

Re: combobox items + value özelligi olan

Mesaj gönderen abdulkadir »

Battosai yazdı:Aslında MyComboBox1.Items.AddX('Abdulkadir','2006'); şeklinde ekleme yapılabilen bir özellik eklerseniz daha şık olurdu bu MyCombobox...
Sende haklısın :D
geliştirmeye yönelik çok seyler yapılabilir.
bence ihtiyacı karsılıyorsa en basitve anlasılır sekilde kullanmak daha verimlidir.

Zaman bulursam eklerim inş.
Fikirleri Aktar
Kaynakları Dagıt
Ve
Yoldan Çekil
http://www.Leventler.com.tr
Kullanıcı avatarı
Battosai
Üye
Mesajlar: 1316
Kayıt: 01 Eki 2007 12:02
Konum: Ankara

Re: Value Ozelligi olan ComboBox

Mesaj gönderen Battosai »

Biraz da bizim katkımız olsun dedim ve bir kaç özellik ekleyip düzenledim unit'i...

Kod: Tümünü seç

unit ValueComboBox;

interface

uses
  SysUtils, Classes, Controls, StdCtrls;

type
  TValComboBox = class(TComboBox)
  private
    { Private declarations }
    FValues: TStrings;
    procedure SetValues(Value: TStrings);
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure AddX(Caption,Value:string);
    procedure ClearX;
    function GetSelectedValue:string;
    procedure SavetoFileEx(const FileName:string);
    procedure LoadFromFileEx(const FileName:string);
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Values: TStrings read FValues write SetValues;
  end;

procedure Register;

implementation
procedure TValComboBox.AddX(Caption, Value: string);
begin
Items.Add(Caption);
Values.Add(Value);
end;

procedure TValComboBox.ClearX;
begin
items.Clear;
Values.Clear;
end;

constructor TValComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FValues := TStringList.Create;
  Style := csDropDownList;
end;

destructor TValComboBox.Destroy;
begin
  TStringList(FValues).OnChange := nil;
  FValues.Free;
  inherited Destroy;
end;


function TValComboBox.GetSelectedValue: string;
begin
Result:='';
if ItemIndex>-1 then
 Result:=Values.Strings[itemindex];
end;

procedure TValComboBox.LoadFromFileEx(const FileName:string);
var
Slist:TStringList;
S,Caption,Value:string;
i:integer;
begin
  try
    items.Clear;
    Values.Clear;
    Slist:=TStringList.Create;
    Slist.LoadFromFile(FileName);
    if Slist.Text<>'' then
     Begin
        for i:= 0 to Slist.Count-1 do
          Begin
            S:=Slist.Strings[i];
            Caption:=copy(S,1,pos(':=',S)-1);
            Value:=copy(S,Pos(':=',S)+2,length(S));
            Items.Add(Caption);
            Values.Add(Value);
          End;
     End;
  Finally
  FreeAndNil(Slist);
  End;
end;

procedure TValComboBox.SavetoFileEx(const FileName:string);
var
slist:TStringList;
i,count:integer;
begin
 try
  slist:=TStringList.Create;
  count:=items.Count;
   if items.Count>Values.Count then
    Begin
      count:=Values.Count;
    End;
  for i :=0 to Count-1 do
   Begin
      slist.Add(Items.Strings[i]+':='+Values.Strings[i]);
    End;
    slist.SaveToFile(FileName);
  Finally
   FreeAndNil(slist);
  End;
end;

procedure TValComboBox.SetValues(Value: TStrings);
begin
  FValues.Assign(Value);
end;

procedure Register;
begin
  RegisterComponents('Samples', [TValComboBox]);
end;

end.

Yeni eklenenler özellikler;

Kod: Tümünü seç

ValCombobox.AddX('Ankara','06'); // yeni kayıt girdik Ankara değerine  value olarak 06 atadık...
ValCombobox.clearX; // items ve values birlikte temizler...bu bileşen için clear yerine kullanılması uygundur..
ValCombobox.SavetoFileEx('C:\test.txt'); // başlık ve değeri yan yana kayıt eder....örn Ankara:=06 şeklinde...
ValCombobox.LoadFromFileEx('C:\test.txt');//  Ankara:=06 olarak kayıt edilen içeriği items ve values değerleri şeklinde yükler...
ValCombobox.GetSelectedValue; // Seçili kayıtın value değerine döndürür...
abdulkadir
Kıdemli Üye
Mesajlar: 489
Kayıt: 13 Eyl 2003 09:10
Konum: istanbul
İletişim:

Re: Value Ozelligi olan ComboBox

Mesaj gönderen abdulkadir »

Ellerine saglık
dahada gelistirmek için bir sınır yoktur.
herkes ihtiyacını ekler ve kullanır. :)
sevgiler...
Fikirleri Aktar
Kaynakları Dagıt
Ve
Yoldan Çekil
http://www.Leventler.com.tr
Kullanıcı avatarı
sadettinpolat
Moderator
Mesajlar: 2130
Kayıt: 07 Ara 2003 02:51
Konum: Ankara
İletişim:

Re: Value Ozelligi olan ComboBox

Mesaj gönderen sadettinpolat »

delphi 8 ve ustu kullaniyosaniz class helper ile de boyle bisi yapmak mumkun. class helper ile yapmanin avantaji projeye yeni bir bilesen eklememek olacaktir.

http://stackoverflow.com/questions/2533 ... ss-helpers
"Sevmek, ne zaman vazgececegini bilmektir." dedi, bana.

---
http://sadettinpolat.blogspot.com/
mehmetantalya
Üye
Mesajlar: 189
Kayıt: 30 Eyl 2013 10:17

Re: Value Ozelligi olan ComboBox

Mesaj gönderen mehmetantalya »

Bu combobox a checkbox ozelligide eklemek mumkun mudur acaba?
Cevapla