Author: Jonas Bilinkevicius
How can I change the language driver of a Paradox table at runtime?
Answer:
The following code should to that:
1 procedure SetLanguage(Tbl: TTable; Lang: DbiName);
2 var
3 pOptDesc: pFLDDesc;
4 pOptData: pBYTE;
5 hDb: hDbiDb;
6 TblDesc: CRTblDesc;
7 Dir: string;
8 begin
9 pOptDesc := AllocMem(sizeof(FLDDesc));
10 pOptData := AllocMem(20);
11 SetLength(Dir, dbiMaxNameLen + 1);
12 Tbl.Active := True;
13 Check(DbiGetDirectory(Tbl.DBHandle, False, PChar(Dir)));
14 SetLength(Dir, StrLen(PChar(Dir)));
15 try
16 FillChar(TblDesc, sizeof(CRTblDesc), #0);
17 Tbl.DisableControls;
18 Tbl.Close;
19 Check(DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl, nil, 0, nil, nil,
20 hDb));
21 Check(DbiSetDirectory(hDb, PChar(Dir)));
22 pOptDesc.iOffset := 0;
23 pOptDesc.iLen := Length(Lang) + 1;
24 StrPCopy(pOptDesc.szName, 'LANGDRIVER');
25 StrPCopy(PChar(pOptData), Lang);
26 TblDesc.iOptParams := 1;
27 TblDesc.pfldOptParams := pOptDesc;
28 TblDesc.pOptData := pOptData;
29 StrPCopy(TblDesc.szTblName, Tbl.TableName);
30 StrCopy(TblDesc.szTblType, szParadox);
31 Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
32 finally
33 Check(DbiCloseDatabase(hDb));
34 FreeMem(pOptDesc, sizeof(FLDDesc));
35 FreeMem(pOptData, 20);
36 Tbl.EnableControls;
37 end;
38 end;
|