• 0
Sign in to follow this  
gleiston

Reindexar Tabela

Question

estou a procura de algum código para reindexar minhas tabelas no inicio da aplicação, em função de constante queda de energia.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Procedure Reindexar(DataBase : TDatabase; Tabela : TTable);

var

List : TStrings;

i : Integer;

begin

try

Database.Connected:=true;

except

Raise;

Exit;

end;

List:=TStringList.create;

session.GetTableNames(DataBase.aliasName, '', true, false,List);

for i:= 0 to List.Count - 1 do

begin

if (Entidade2) then

break;

application.ProcessMessages;

Tabela.close;

Tabela.TableName:=List;

Try

Tabela.open;

Check(dbiRegenIndexes(Tabela.Handle));

except

Raise;

end;

end;

List.Free;

Database.Connected:=false;

end;

Para executar a rotina você pode Incluir quando sua aplicação esta sendo iniciada

Adicionando a seguinte linha.

No evento oncreate do Datamodulo

Reindexar(Dados,Table1); //Dados Nome imposto por mim ao componente Database e Table1 o componente inserido na aplicação.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this