![]() |
|
Create ListBoxItem - Baskı Önizleme +- Delphi Can (https://www.delphican.com) +-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3) +--- Forum: Mobil Platform - FireMonkey (FMX) (https://www.delphican.com/forumdisplay.php?fid=7) +--- Konu Başlığı: Create ListBoxItem (/showthread.php?tid=1827) Sayfalar:
1
2
|
Create ListBoxItem - Dostk - 15-01-2018 Selam. Combobox içindeki ListBoxItem kullanarak databasedeki kullanıcı adlarını çekmek için aşağıdaki kodları kullanıyorum. Fakat sıkıntı ise databasede kaç kullanıcı olduğunu bilmediğim için ListBoxItem Create yöntemiyle bunu nasıl çözebilirim? Örnek: ListBoxItem+ ekle.Text:= FieldByName('USERNAME').AsString // ListBoxItem1.Text ListBoxItem+ ekle.Text:= FieldByName('USERNAME').AsString // ListBoxItem2.Text ListBoxItem+ ekle.Text:= FieldByName('USERNAME').AsString // ListBoxItem3.Text procedure TForm1.UserComboBoxListele(Sender: TObject);
var
Ekle: Integer;
ListBoxItem: TListBoxItem;
begin
try
With QUser do
begin
Active := False;
Connection := Connection;
Close;
SQL.Clear;
SQL.Add('Select * From USERS');
Prepared := True;
Open;
if Not IsEmpty then
begin
Ekle := 0;
ListBoxItem := TListBoxItem.Create(ListBoxItem);
while Not QUser.Eof do
begin
Ekle := +1;
ListBoxItem + Ekle.Text := FieldByName('USERNAME').AsString;
// Kadi.Text := FieldByName('USERNAME').AsString;
// ComboBox1.Items.Add(FieldByName('USERNAME').AsString);
Next;
end;
end;
end;
finally
QUser.Close;
end;
end;
Cvp: Create ListBoxItem - savasabd - 15-01-2018 Query'nin RecordCount özelliği satır sayısını dolayısıyla da kullanıcı sayısını verir. Create ListBoxItem - Abdullah ILGAZ - 15-01-2018 Merhaba, if not IsEmpty kontrolünüz ve while not EOF döngünüz yerine; Savaş Bey'in söylediği gibi, QUser.RecordCount değerinin 0 (sıfır)dan büyük olması durumunda for döngüsü ile bu işlemleri kolaylıkla yapabilirsiniz. if QUser.RecordCount > 0 then ... Create ListBoxItem - Dostk - 15-01-2018 Sanrım sorum yanlış anlaşıldı. Sorun kullanıcıları listelemede değil. Databasede kullanıcı sayısını bilmediğim için ListBoxItem1.Text, ListBoxItem2.Text , ListBoxItem3.Text diye Create etmek istiyorum. sadece ListBoxItem1.Text varsa u seferde databasedeki bir kullanıcının adı listeleniyor diğerleri listelenmiyor. Cvp: Create ListBoxItem - Abdullah ILGAZ - 15-01-2018 (15-01-2018, Saat: 11:45)Dostk Adlı Kullanıcıdan Alıntı: Sanrım sorum yanlış anlaşıldı. Sorun kullanıcıları listelemede değil. procedure TForm1.UserComboBoxListele(Sender: TObject);
var
Ekle: Integer;
ListBoxItem: TListBoxItem;
begin
try
With QUser do
begin
Active := False;
Connection := Connection;
Close;
SQL.Clear;
SQL.Add('Select * From USERS');
Prepared := True;
Open;
for i := 0 to QUser.RecordCount-1 do
begin
ListBoxItem := TListBoxItem.Create(ListBox1);
ListBoxItem.Parent := ListBox1;
ListBoxItem.Text := QUser.FieldByName('USERNAME').AsString + (i+1).ToString; // kaçıncı bilgisi burada tutulabilir?
QUser.Next;
end; //for
end; //withdo
end; //try
finally
QUser.Close;
end;
end;
Cvp: Create ListBoxItem - SimaWB - 15-01-2018 (15-01-2018, Saat: 11:45)Dostk Adlı Kullanıcıdan Alıntı: Sanrım sorum yanlış anlaşıldı. Sorun kullanıcıları listelemede değil. Kodunuzda TListBoxItem.Create'i kullanmışsınız. Parametre olarak da ListBoxItem'ı geçmişsiniz. Bu parametre ne işi yarar, neden kullandınız? Cvp: Create ListBoxItem - Fesih ARSLAN - 15-01-2018 Merhaba, Abdullah Bey'in vermiş olduğu kod sanırım işinizi görecektir. İlle de oluşturduğum her Item'a bir isim vermek istiyorum (Daha sonraki işlemlerde Item adı kullanılabilir) derseniz; Ekle := +1;satırından hemen sonraki iki satırı aşağıdaki şekilde değiştirmeniz yeterli olacaktır. ListBoxItem.Name := 'ListBoxItem' + Ekle.ToString;
ListBoxItem.Text := FieldByName('USERNAME').AsString;
Cvp: Create ListBoxItem - Dostk - 15-01-2018 İlgilenen herkese teşekkür ederim, Fakat sorunu halen çözemedim. Create(ListBox1); hata alıyorum foruma ListBox1 eklersem sorun yok, ama bu seferde istediğim gibi combobox'a kullanıcıları listeleyemiyorum. procedureTForm1.UserComboBoxListele(Sender: TObject);
var
Ekle: Integer;
ListBoxItem: TListBoxItem;
begin
try
With QUser do
begin
Active := False;
Connection := Connection;
Close;
SQL.Clear;
SQL.Add('Select * From USERS');
Prepared := True;
Open;
for I := 0 to QUser.RecordCount - 1 do
begin
Ekle := +1;
ListBoxItem := TListBoxItem.Create(ListBox1);
ListBoxItem.Parent := ListBox1;
ListBoxItem.Name := 'ListBoxItem' + Ekle.ToString;
ListBoxItem.Text := FieldByName('USERNAME').AsString;
// ListBoxItem.Text := QUser.FieldByName('USERNAME').AsString + (I + 1)
// .ToString; // kaçıncı bilgisi burada tutulabilir?
QUser.Next;
end; // for
end; // withdo
finally
QUser.Close;
end;
Cvp: Create ListBoxItem - savasabd - 15-01-2018 Listbox'ı değil Listbox'ın itemini oluşturuyorsunuz,dolayısıyla hata almanız normal.Listbox'ı oluşturmak için Listbox1 := TListBox.Create(self); Listbox1.Parent := self;kodunu yazmalısınız ama combobox için neden ListBoxItem kullanmanız gerekiyor anlaymadım.ComboBox'a item eklemek için şu kodu kullanabilirsiz: ComboBox1.Items.Add('');
yada benim kaçırdığım bir şeyler var.
Cvp: Create ListBoxItem - mcuyan - 15-01-2018 Merhaba.. Listbox Neden kullandığınızı anlamadım fakat bu tür işleri genel de Combobox ile yapıyorum ben..
q1:='Select username from Kullanicilar';
q1.open;
q1.first;
while Not q1.eof do
begin
Combobox1.Items.Add(Q1.FieldByName('username').asstring);
q1.next;
end;
Q1.Close;
|