(Co-Admin)
Registriert seit: 7. Jun 2002
Ort: Owingen
5.865 Beiträge
Delphi 2010 Professional
|
25. Jun 2003, 08:19
Hallo FBrust,
Informationen wie z.B. Vorgabewerte werden in einer internen Struktur CRTblDesc gespeichert. Diese kann man mit dem Aufruf der function DbiDoRestructure ändern.
Hier ein Beispiel aus der OH zur BDE 4.0:
Delphi-Quellcode:
procedure fDbiDoRestructure(Tbl: TTable; Field: TField; MinVal, MaxVal, DefVal: pLongint; Required: Bool);
var
hDb: hDbiDb;
TblDesc: CRTblDesc;
VChk: pVChkDesc;
Dir: String;
NumVChks: Word;
OpType: CROpType;
begin
NumVChks := 0;
SetLength(Dir, dbiMaxNameLen + 1);
Check(DbiGetDirectory(Tbl.DBHandle, False, PChar(Dir)));
SetLength(Dir, StrLen(PChar(Dir)));
VChk := AllocMem(sizeof(VChkDesc));
try
FillChar(TblDesc, sizeof(CRTblDesc), #0);
VChk.iFldNum := Field.Index + 1;
Tbl.DisableControls;
Tbl.Close;
Check(DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl, nil, 0, nil, nil, hDb));
Check(DbiSetDirectory(hDb, PChar(Dir)));
with VChk^ do
begin
bRequired := Required;
if MinVal <> nil then
begin
Inc(NumVChks);
bHasMinVal := True;
move(MinVal^, aMinVal, sizeof(MinVal^));
end
else
bHasMinVal := False;
if MaxVal <> nil then
begin
Inc(NumVChks);
bHasMaxVal := True;
move(MaxVal^, aMaxVal, sizeof(MaxVal^));
end
else
bHasMaxVal := False;
if DefVal <> nil then
begin
Inc(NumVChks);
bHasDefVal := True;
move(DefVal^, aDefVal, sizeof(DefVal^));
end
else
bHasDefVal := False;
end;
TblDesc.iValChkCount := NumVChks;
TblDesc.pVChkDesc := VChk;
OpType := crADD;
TblDesc.pecrValChkOp := @OpType;
StrPCopy(TblDesc.szTblName, Tbl.TableName);
StrCopy(TblDesc.szTblType, szParadox);
Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
finally
Check(DbiCloseDatabase(hDb));
FreeMem(VChk, sizeof(VChkDesc));
Tbl.EnableControls;
Tbl.Open;
end;
end;
[edit=MrSpock]Beispiel hinzugefügt[/edit]
Albert Live long and prosper
MrSpock
|
|
Zitat
|