We help IT Professionals succeed at work.

Reseting autoincrement in paradox tables

oneeye
oneeye asked
on
1,421 Views
Last Modified: 2010-08-05
Hi,

As part of a new project, I'm using a table I defined for an old project.... I would like to reset the autoincrement back to 1, but I can't seem to do it.

Emptying the database doesn't reset it, nor does changing the definition of the field, if I change it back, the autoincrement pops back to it's former value.

Any clues?

Oneeye
Comment
Watch Question

Top Expert 2004

Commented:
this may help,
the path and filename of the table is needed,
no one may have access to the file during operation
(use 0 for reset or (wantedstartnumber-1) for any value

unit pd_autoinc_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids, DBGrids, Db, DBTables;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


Procedure SetAutoInc(filename : string; Value : Longint);
var
  mystream : tfilestream;
begin
  mystream := tfilestream.create(filename,
              fmOpenWrite + fmShareExclusive);
  try
    mystream.Seek(73, soFromBeginning);
    mystream.Writebuffer(Value, SizeOf(Value));
  finally
    mystream.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Table1.Close;
  SetAutoInc('C:\Test\Test.db',StrtoInt(edit1.text));
  Table1.Open;
end;

end.

hope this helps

meikl ;-)
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Igor UL7AAjrSenior developer

Commented:
meikl :-)

do you mean that there is no legal way to reset autoinc field?

-----
Igor.
Top Expert 2004

Commented:
no legal way, this way is also published by borland
-> serching for the link . . .
Top Expert 2004

Commented:
Igor UL7AAjrSenior developer

Commented:
thanx meikl,
I never know that there is no "legal" way, really.

----
Igor.

Author

Commented:
Will give it a try... stand by one...

Ah, that's got it. Thanks...

Author

Commented:
Did the trick, sorry, I thought I had marked it as answered.
Top Expert 2004

Commented:
seems to be a grading by mistake, or?

Commented:
Yes. :-)  I will ask this on Community Support Topic.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.