Kolejny raz zwracam sie o pomoc do forumowiczów 4programmers, bo brak mi już cierpliwości i sam nie wiem już gdzie robię błąd.
Poniższy kod odpowiada za dopasowanie ilości wierszy tabeli do liczby wybranej przez użytkownika w kontrolce ComboBox. Jednak po takiej operacji indeksy nie mają charakteru porządkowego, należy tabelę "spakować". I tu pojawia się zasadniczy problem. Ciągle wywala błędy.
procedure TForm3.ComboBox3Change(Sender: TObject);
var i,j,k :Integer;
begin
i:=0;
Table1.First;
while not Table1.Eof do
begin
Inc(i);
Table1.Next
end;
edit2.Text:=inttostr(i);
j:=StrToInt(ComboBox3.Text);
if j>i then
begin
Table1.Last;
for k:=1 to j-i do
begin
Table1.Insert;
Table1.Post
end;
end;
if j<i then
begin
for k:=j to i-1 do
begin
Table1.Last;
Table1.Delete;
end;
end;
Table1.Active:=false;
Table1.Exclusive:=true;
PackTable(Table1);
Table1.Active:=True;
end;
Procedura pakowania tabeli pobrana ze strony Borland'a http://info.borland.com/devsupport/bde/bdeapiex/dbidorestructure.html
begin
// Make sure the table is open exclusively so we can get the db handle...
if Table.Active = False then
raise EDatabaseError.Create('Table must be opened to pack');
if Table.Exclusive = False then
raise EDatabaseError.Create('Table must be opened exclusively to pack');
// Get the table properties to determine table type...
Check(DbiGetCursorProps(Table.Handle, Props));
// If the table is a Paradox table, you must call DbiDoRestructure...
if Props.szTableType = szPARADOX then
begin
// Blank out the structure...
FillChar(TableDesc, sizeof(TableDesc), 0);
// Get the database handle from the table's cursor handle...
Check(DbiGetObjFromObj(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
// Put the table name in the table descriptor...
StrPCopy(TableDesc.szTblName, Table.TableName);
// Put the table type in the table descriptor...
StrPCopy(TableDesc.szTblType, Props.szTableType);
// Set the Pack option in the table descriptor to TRUE...
TableDesc.bPack := True;
// Close the table so the restructure can complete...
Table.Close;
// Call DbiDoRestructure...
Check(DbiDoRestructure(hDb, 1, @TableDesc, nil, nil, nil, FALSE));
end
else
// If the table is a dBASE table, simply call DbiPackTable...
if Props.szTableType = szDBASE then
Check(DbiPackTable(Table.DBHandle, Table.Handle, nil, szDBASE, TRUE))
else
// Pack only works on PAradox or dBASE; nothing else...
raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' +
'type to pack');
Table.Open;
end;
"Table must be opened to pack." to błąd jaki wyskakuje przy obecnej konfiguracji, jeśli zmienię na
Table1.Active:=True;
Table1.Exclusive:=true;
PackTable(Table1);
"Cannot perform this operation on an open dataset"
natomiast jeśli nie wywołam Table1.Exclusive to wyskakuje błąd
"Table must be opened Exclusively to pack"
Proszę o pomoc bo brak mi już pomysłów.
</delphi></i>