PARADOX DB's & INDEXES!!!!!AHHHHH

PLEASE, can you help me sort out this trivial and damn annoying problem of mine.  Here's a little bit of simple code....

With FieldDefs do begin
  Clear;
  Add('ConsignmentNumber', ftString, 30, True);
  Add('DateTime', ftDateTime, 0, True);
  With IndexDefs do begin
    Clear;
    Add('', 'ConsignmentNumber', []);
    Add('DateTimeIndex', 'DateTime', []);
  End;
End;

That's just to create a simple table with 2 fields, both of which are indexed.  Now, here's the problem.  This works....

tblMain.IndexName:='';

That restores the primary index, but if I do this....

tblMain.IndexName:='DateTimeIndex';

It doesn't work!!!!!!

Please, why?
LVL 6
JaymolAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mhervaisCommented:
you should issue the update method like this


With FieldDefs do begin
  Clear;
  Add('ConsignmentNumber', ftString, 30, True);
  Add('DateTime', ftDateTime, 0, True);
  With IndexDefs do begin
    Clear;
    Add('', 'ConsignmentNumber', []);
    Add('DateTimeIndex', 'DateTime', []);
    update; <-----
  End;
End;

so that the new content would be knowned.

regards,Marc
0
JaymolAuthor Commented:
Thanks Marc, but that's not the answer.  That's something I left out of the code on THIS page, but not in the program.
0
mhervaisCommented:
Maybe you write down a real part of code so that we can see what's missing?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

kretzschmarCommented:
hi jaymol,

With FieldDefs do begin
  Clear;
  Add('ConsignmentNumber', ftString, 30, True);
  Add('DateTime', ftDateTime, 0, True);
  With IndexDefs do begin
    Clear; //<---do this not clear also the fielddefs?
    Add('', 'ConsignmentNumber', []);
    Add('DateTimeIndex', 'DateTime', []);
  End;
End;

does this change then work?

With FieldDefs do begin
  Clear;
  Add('ConsignmentNumber', ftString, 30, True);
  Add('DateTime', ftDateTime, 0, True);
end;
With IndexDefs do begin
  Clear;
  Add('', 'ConsignmentNumber', []);
  Add('DateTimeIndex', 'DateTime', []);
End;

meikl
0
JaymolAuthor Commented:
No, it doesn't clear the FieldDefs.  The problem is that the program reports there is no Index defined with the name I have given, but all the data is there in the correct fields.
0
kretzschmarCommented:
hi jaymol,

maybe you should use the
ttable-method addindex to create an index.

meikl
0
JaymolAuthor Commented:
I'll try that and return....Thanks.
0
JaymolAuthor Commented:
Nope.  It still doesn't work.  What I'm trying to do is create a table with 2 fields that can be used as the main index - ConsignmentNumber and DateTime.  I need to be able to switch between these 2 indexes at any time, therefore sorting the records in 2 different ways.  None of the above seems to work with Paradox tables.

Any more ideas?

John.
0
kretzschmarCommented:
hi jaymol,

i will provide you a sample in ~4-5 hours, when i'm at home and its not solved in the meantime.

meikl
0
JaymolAuthor Commented:
Thanks meikl.  Look forward to that.
0
kretzschmarCommented:
hi jaymol,

here the first version

procedure TForm1.Button2Click(Sender: TObject);
begin
  Table1.Close;
  query1.DatabaseName := Table1.DatabaseName;
  query1.sql.Clear;  //easiest method to add fields
  query1.sql.Add('alter table address add IntField Integer, add DateField Date');
  try
    query1.ExecSQL;
    Table1.Exclusive := True;  //must be exclusive opened
    Table1.Open;
    Table1.AddIndex('','IntField',[]);  //Paradox 4 Tabletype ->
    Table1.AddIndex('','DateField',[]);  //never give the index a name
    Table1.IndexDefs.Update;
    Table1.IndexName := 'DateField';  //name is then equal fieldname
  except
    //ErrorHandling
  end;
end;

remark
the ..defs propertys are only for creating
a new table or adding calculated fields
and will not force a restructure af the table

try it

meikl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rovermCommented:
What do you see when you open this newly created table in the Database Desktop ?

grtx, Mark
0
kretzschmarCommented:
? roverm, what do you mean ?
0
rovermCommented:
I mean: after you have created the table at run-time, start the Database Desktop and look at the table's structure.
I think that one of the index names may not be right (for the BDE).
In the Database Desktop you can see that !

grtx, Mark
0
kretzschmarCommented:
hi roverm,

i do not create a table, i add on an existing table, which has already a primary index and some fields, two fields and create for this fields each a secondary standard index.

please review the question

meikl
0
rovermCommented:
Sorry, didn't read it correct !
You know that in a paradox table all
indexes must be at the top of your table! You describe that you already have a table with one indexed field (the first in the table), some other fields and so on.
Is the DateTimeIndex the second field?

grtx, Mark
0
rovermCommented:
Sorry, didn't read it correct !
You know that in a paradox table all
indexes must be at the top of your table! You describe that you already have a table with one indexed field (the first in the table), some other fields and so on.
Is the DateTimeIndex the second field?

grtx, Mark
0
kretzschmarCommented:
hi roverm,

the fieldorder doesn't matter on a secondary index

let say we've a table address with this structure

id -> primary index
name
street
city
and more fields
....

now i will append two fields at runtime.
lets say Remark and Birthday

procedure TForm1.Button2Click(Sender: TObject);
begin
  Table1.Close;
  query1.DatabaseName := Table1.DatabaseName;
  query1.sql.Clear;  //easiest method to add fields
  query1.sql.Add('alter table address add Remark Char(50), add BirthDay Date');
  try
    query1.ExecSQL;
    Table1.Exclusive := True;
    Table1.Open;
    Table1.AddIndex('','Remark',[]);  //Paradox 4
    Table1.AddIndex('','BirthDay',[]);  //never give the index a name
    Table1.IndexDefs.Update;
    Table1.IndexName := 'BirthDay';     //<-Sort by BirthDay
  except
    //ErrorHandling
  end;
end;

now i've added the two fields on the table and created the secondary indexes on this two fields, which i can use to show the table ordered by Birthday or ordered by Remark by setting the Table.Indexname.

thats all

meikl
0
JaymolAuthor Commented:
Kretzschmar - I've tried sooooo many different combinations of ideas on this page and still, I cannot solve the problems I get EVERY TIME!!!  AHHHH!

Okay.  Could you give me a brief example (using only a TTable - No TQuery) on creating a table with field names "Field1", "Field2", and "Field3" and then create a primary and secondary index, "Field1" primary, and "Field2" secondary.  I'll give you the points cos you've given the most constructive suggestions.

Thanks for your help,

John.
0
JaymolAuthor Commented:
Actually, forget it.  Using bits of code posted here, I've managed to get it working AT LAST!!!!!  (Bloody BDE & Paradox!)

Anyway, thanks EVERYONE who posted suggestions (apart from the crap ones), and thanks Meikl.  You did it baby!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.