Deprecated: Assigning the return value of new by reference is deprecated in /home/exampled/public_html/wp-includes/cache.php on line 99

Deprecated: Assigning the return value of new by reference is deprecated in /home/exampled/public_html/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/exampled/public_html/wp-includes/theme.php on line 576
Comments on: Fill the Combobox Items from Dataset http://exampledelphi.com/delphi.php/tips-and-tricks/fill-the-combobox-items-from-dataset/ Delphi Examples Collection Tue, 07 Feb 2012 15:30:58 +0000 http://wordpress.org/?v=2.5 By: Steve Faleiro http://exampledelphi.com/delphi.php/tips-and-tricks/fill-the-combobox-items-from-dataset/#comment-1530 Steve Faleiro Fri, 19 Aug 2011 12:36:43 +0000 http://exampledelphi.com/delphi.php/uncategorized/fill-the-combobox-items-from-dataset/#comment-1530 (moderator please delete first two posts of mine.) The following code does this better. You can select a value and display column. Also a method to free the memory allocated for the value objects. Code by Steve Faleiro steve_goa@yahoo.com. procedure disposeComboBoxObjects(c: TComboBox); var i: integer; begin if c.Items.Count > 0 then for i := 0 to c.Items.Count - 1 do Dispose(PVariant(c.Items.Objects[i])); end; // ---- Populate a Combobox --------------------------------------------- // ---- for accessing the value, use: // var // s : PVariant; // begin // s := PVariant( lstServers.Items.Objects[lstServers.ItemIndex] ); // my_key := integer( s ^ ); // cast to your type // --------------------------------------------------------------------- procedure populateComboBox(c: TComboBox; ds: TDataSet; KeyColumnIndex, DisplayColumnIndex: integer); var v: variant; pt: PVariant; begin disposeComboBoxObjects(c); c.Items.Clear; with ds do begin First; while not EOF do begin v := Fields[KeyColumnIndex].Value; New(pt); pt ^ := v; c.Items.AddObject(Fields[DisplayColumnIndex].AsString, TObject(pt)); Next; end; end; if c.Items.Count > 0 then c.ItemIndex := 0; end; (moderator please delete first two posts of mine.)

The following code does this better. You can select a value and display column. Also a method to free the memory allocated for the value objects.
Code by Steve Faleiro steve_goa@yahoo.com.

procedure disposeComboBoxObjects(c: TComboBox);
var
i: integer;
begin
if c.Items.Count > 0 then
for i := 0 to c.Items.Count - 1 do
Dispose(PVariant(c.Items.Objects[i]));
end;

// —- Populate a Combobox ———————————————
// —- for accessing the value, use:
// var
// s : PVariant;
// begin
// s := PVariant( lstServers.Items.Objects[lstServers.ItemIndex] );
// my_key := integer( s ^ ); // cast to your type
// ———————————————————————
procedure populateComboBox(c: TComboBox; ds: TDataSet;
KeyColumnIndex, DisplayColumnIndex: integer);
var
v: variant;
pt: PVariant;
begin

disposeComboBoxObjects(c);
c.Items.Clear;

with ds do begin
First;
while not EOF do begin
v := Fields[KeyColumnIndex].Value;
New(pt);
pt ^ := v;
c.Items.AddObject(Fields[DisplayColumnIndex].AsString, TObject(pt));
Next;
end;
end;

if c.Items.Count > 0 then
c.ItemIndex := 0;
end;

]]>
By: Steve Faleiro http://exampledelphi.com/delphi.php/tips-and-tricks/fill-the-combobox-items-from-dataset/#comment-1529 Steve Faleiro Fri, 19 Aug 2011 12:34:23 +0000 http://exampledelphi.com/delphi.php/uncategorized/fill-the-combobox-items-from-dataset/#comment-1529 Once again: procedure disposeComboBoxObjects(c: TComboBox); var i: integer; begin if c.Items.Count > 0 then for i := 0 to c.Items.Count - 1 do Dispose(PVariant(c.Items.Objects[i])); end; // ---- Populate a Combobox --------------------------------------------- // ---- for accessing the value, use: // var // s : PVariant; // begin // s := PVariant( lstServers.Items.Objects[lstServers.ItemIndex] ); // my_key := integer( s ^ ); // 0 then c.ItemIndex := 0; end; Once again:

procedure disposeComboBoxObjects(c: TComboBox);
var
i: integer;
begin
if c.Items.Count > 0 then
for i := 0 to c.Items.Count - 1 do
Dispose(PVariant(c.Items.Objects[i]));
end;

// —- Populate a Combobox ———————————————
// —- for accessing the value, use:
// var
// s : PVariant;
// begin
// s := PVariant( lstServers.Items.Objects[lstServers.ItemIndex] );
// my_key := integer( s ^ ); // 0 then
c.ItemIndex := 0;
end;

]]>
By: Steve Faleiro http://exampledelphi.com/delphi.php/tips-and-tricks/fill-the-combobox-items-from-dataset/#comment-1528 Steve Faleiro Fri, 19 Aug 2011 12:32:20 +0000 http://exampledelphi.com/delphi.php/uncategorized/fill-the-combobox-items-from-dataset/#comment-1528 The following code does this better. You can select a value and display column. Also a method to free the memory allocated for the value objects. Code by Steve Faleiro steve_goa@yahoo.com. procedure disposeComboBoxObjects(c: TComboBox); var i: integer; begin if c.Items.Count > 0 then for i := 0 to c.Items.Count - 1 do Dispose(PVariant(c.Items.Objects[i])); end; // ---- Populate a Combobox --------------------------------------------- // ---- for accessing the value, use: // var // s : PVariant; // begin // s := PVariant( lstServers.Items.Objects[lstServers.ItemIndex] ); // my_key := integer( s ^ ); // 0 then c.ItemIndex := 0; end; The following code does this better. You can select a value and display column. Also a method to free the memory allocated for the value objects.
Code by Steve Faleiro steve_goa@yahoo.com.

procedure disposeComboBoxObjects(c: TComboBox);
var
i: integer;
begin
if c.Items.Count > 0 then
for i := 0 to c.Items.Count - 1 do
Dispose(PVariant(c.Items.Objects[i]));
end;

// —- Populate a Combobox ———————————————
// —- for accessing the value, use:
// var
// s : PVariant;
// begin
// s := PVariant( lstServers.Items.Objects[lstServers.ItemIndex] );
// my_key := integer( s ^ ); // 0 then
c.ItemIndex := 0;
end;

]]>