Algum Programador de VB consegue passar esse cod. p/ delphi?
Private Function teste()
Dim dbs As Database
Dim tdf As TableDef
Dim idx As Index
Dim fld As Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs(´tblConfiguracoes´)
For Each idx In tdf.Indexes
For Each fld In idx.Fields
MsgBox ´Índice: ´ & idx.Name & ´ ´ & vbNewLine & _
´Campo: ´ & fld.Name
Next fld
Next idx
Set fld = Nothing
Set idx = Nothing
Set tdf = Nothing
Set dbs = Nothing
End Function
Dim dbs As Database
Dim tdf As TableDef
Dim idx As Index
Dim fld As Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs(´tblConfiguracoes´)
For Each idx In tdf.Indexes
For Each fld In idx.Fields
MsgBox ´Índice: ´ & idx.Name & ´ ´ & vbNewLine & _
´Campo: ´ & fld.Name
Next fld
Next idx
Set fld = Nothing
Set idx = Nothing
Set tdf = Nothing
Set dbs = Nothing
End Function
Programadorjlle
Curtidas 0
Respostas
Anonymous
26/03/2003
Exemplo em ADO
procedure ExecuteSQL(ExeSQL, MSGERR: String; Conex : TADOConnection);
begin
with TADOQuery.Create(Application) do begin
try
Connection :=Conex;
Close;
SQL.Add(ExeSQL);
//Se o comando SQL for update, insert, delete
ExecSQL;
//Se o comando SQL for select
Open;
Free;
except
on e : exception do
MessageDlg(MSGERR+#13+PChar(E.Message)+13+PChar(SQL.Text), mtError, [mbOk], 0);
end;
end;
end;
procedure ExecuteSQL(ExeSQL, MSGERR: String; Conex : TADOConnection);
begin
with TADOQuery.Create(Application) do begin
try
Connection :=Conex;
Close;
SQL.Add(ExeSQL);
//Se o comando SQL for update, insert, delete
ExecSQL;
//Se o comando SQL for select
Open;
Free;
except
on e : exception do
MessageDlg(MSGERR+#13+PChar(E.Message)+13+PChar(SQL.Text), mtError, [mbOk], 0);
end;
end;
end;
GOSTEI 0
Programadorjlle
26/03/2003
Valeu Visitante muito Obrigado 8)
GOSTEI 0
Aroldo Zanela
26/03/2003
Valeu Visitante muito Obrigado 8)
Colega,
A resposta do visitante não tem nada a ver com sua pergunta. Cuidado com quem não se identifica.
GOSTEI 0
Evandro Massini
26/03/2003
Cara , se eu o entendi bem vc quer o nome dos índices para os determinados campos. Então tente o seguinte:
var D:TDatabase;
T:TTAble;
L:TStringlist;
a:integer;
begin
L:=tstringlist.create;
l.add(´database name=´ + ´CaminhodoBancodeDados´);
session.DeleteAlias(´teste´);
session.addalias(´teste´,´msaccess´,l);
d:=tdatabase.create(nil);
d.databasename:=´teste´;
d.loginprompt:=false;
d.Connected :=true;
t:=ttable.Create(nil);
t.DatabaseName :=´teste´;
t.TableName :=´nomedatabela´;
t.Active :=true;
for a:=0 to t.IndexDefs.Count -1 do
begin
showmessage(´Índice= ´ + t.IndexDefs[a].Name + chr(13) + chr(10) + ´Campo= ´ + t.IndexDefs[a].Fields );
end;
end;
Espero ter ajudado...
var D:TDatabase;
T:TTAble;
L:TStringlist;
a:integer;
begin
L:=tstringlist.create;
l.add(´database name=´ + ´CaminhodoBancodeDados´);
session.DeleteAlias(´teste´);
session.addalias(´teste´,´msaccess´,l);
d:=tdatabase.create(nil);
d.databasename:=´teste´;
d.loginprompt:=false;
d.Connected :=true;
t:=ttable.Create(nil);
t.DatabaseName :=´teste´;
t.TableName :=´nomedatabela´;
t.Active :=true;
for a:=0 to t.IndexDefs.Count -1 do
begin
showmessage(´Índice= ´ + t.IndexDefs[a].Name + chr(13) + chr(10) + ´Campo= ´ + t.IndexDefs[a].Fields );
end;
end;
Espero ter ajudado...
GOSTEI 0
Aroldo Zanela
26/03/2003
Colega,
O problema é que não tem nenhuma linha indicando a conexão, deve estar provavelmente em um outro trecho do programa.
Deve existir um objeto que tenha as propriedades para índices e campos
(provavelmente pré definido pelo programador), verifique se o trecho não
está utilizando alguma DLL ou OCX.
Se puder, manda o restante do código.
O problema é que não tem nenhuma linha indicando a conexão, deve estar provavelmente em um outro trecho do programa.
Deve existir um objeto que tenha as propriedades para índices e campos
(provavelmente pré definido pelo programador), verifique se o trecho não
está utilizando alguma DLL ou OCX.
Se puder, manda o restante do código.
GOSTEI 0