Board index » delphi » Strange Thing

Strange Thing

Hi everyone, I am writing a program that take items from a lit box, and
assigns them to a record.
Here is the code I have used
for i := Listbox1.Count -1 downto 0 do
        case i of
          0 : Details.Username := ListBox1.Items.Text[i];
          1 : Details.Pasword := ListBox1.Items.Strings[i];
          2 : Details.Sex := ListBox1.Items.Strings[i];
          3 : Details.Location := ListBox1.Items.Strings[i];
          4 : Details.Personal := ListBox1.Items.Strings[i];
          5 : Details.Email := ListBox1.Items.Strings[i];
          6 : Details.Op := False;

        end; {case}

      end;  {for}

The program then takes the details in the Record and adds it to a ADO
Database, The code I have used for this follows.
with ADOTable1 do begin
        FieldByName('Username').Value := details.Username ;
        FieldByName('Password').Value := details.Pasword ;
        FieldByName('Sex').Value := details.Sex ;
        FieldByName('Location').value := Details.Location;
        FieldByName('Personal Statement').Value := Details.Personal ;
        FieldByName('Email Address').Value := details.Email ;
        FieldByName('Operator').Value := Details.Op;
Now the problem is, when posting this it creates a empty record in the
database, and for the life of me, I have no idea why. Does anyone have any
suggestions on how to correct this?


Re:Strange Thing

First, why don't you skip the for/case construction and write
something like:

Details.Username := ListBox1.Items.Text[0];
Details.Pasword := ListBox1.Items.Strings[1];
Details.Sex := ListBox1.Items.Strings[2];
Details.Location := ListBox1.Items.Strings[3];
Details.Personal := ListBox1.Items.Strings[4];
Details.Email := ListBox1.Items.Strings[5];

What are the parameter-types? They should have type String or
ShortString. You use variant-assignments for ADOTable1. Maybe you
should use string-assignments like "FieldByName('Username').AsString
:= ...". Be sure that you don't mix incompatible datatypes. Don't
expect Delphi to handle all type-conversions properly!



Other Threads