Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Modify the idapi.cfg settings through code Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Modify the idapi.cfg settings through code 28-Oct-02
Category
BDE
Language
Delphi 2.x
Views
273
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Is there a way to change the IDAPI.CFG file from Delphi coding using the BDE API, 
since I wish to avoid having my users utilize the BDECFG.EXE utility?

Answer:

Here is a unit that is supposed to allow changing the config file:

1   unit CFGTOOL;
2   
3   interface
4   
5   uses
6     SysUtils, Classes, DB, DbiProcs, DbiTypes, DbiErrs;
7   
8   type
9     TBDEConfig = class(TComponent)
10    private
11      FLocalShare: Boolean;
12      FMinBufSize: Integer;
13      FMaxBufSize: Integer;
14      FSystemLangDriver: string;
15      FParadoxLangDriver: string;
16      FMaxFileHandles: Integer;
17      FNetFileDir: string;
18      FTableLevel: string;
19      FBlockSize: Integer;
20      FDefaultDriver: string;
21      FStrictIntegrity: Boolean;
22      FAutoODBC: Boolean;
23  
24      procedure Init;
25      procedure SetLocalShare(Value: Boolean);
26      procedure SetMinBufSize(Value: Integer);
27      procedure SetMaxBufSize(Value: Integer);
28      procedure SetSystemLangDriver(Value: string);
29      procedure SetParadoxLangDriver(Value: string);
30      procedure SetMaxFileHandles(Value: Integer);
31      procedure SetNetFileDir(Value: string);
32      procedure SetTableLevel(Value: string);
33      procedure SetBlockSize(Value: Integer);
34      procedure SetDefaultDriver(Value: string);
35      procedure SetAutoODBC(Value: Boolean);
36      procedure SetStrictIntegrity(Value: Boolean);
37      procedure UpdateCFGFile(path, item, value: string);
38  
39    protected
40  
41    public
42      constructor Create(AOwner: TComponent); override;
43      destructor Destroy; override;
44    published
45      property LocalShare: Boolean read FLocalShare write SetLocalShare;
46      property MinBufSize: Integer read FMinBufSize write SetMinBufSize;
47      property MaxBufSize: Integer read FMaxBufSize write SetMaxBufSize;
48      property SystemLangDriver: string read FSystemLangDriver write
49        SetSystemLangDriver;
50      property ParadoxLangDriver: string read FParadoxLangDriver write
51        SetParadoxLangDriver;
52      property MaxFileHandles: Integer read FMaxFileHandles write SetMaxFileHandles;
53      property NetFileDir: string read FNetFileDir write SetNetFileDir;
54      property TableLevel: string read FTableLevel write SetTableLevel;
55      property BlockSize: Integer read FBlockSize write SetBlockSize;
56      property DefaultDriver: string read FDefaultDriver write SetDefaultDriver;
57      property AutoODBC: Boolean read FAutoODBC write SetAutoODBC;
58      property StrictIntegrity: Boolean read FStrictIntegrity write 
59  SetStrictIntegrity;
60  
61    end;
62  
63  procedure register;
64  
65  implementation
66  
67  function StrToBoolean(Value: string): Boolean;
68  begin
69    if (UpperCase(Value) = 'TRUE') or (UpperCase(Value) = 'ON') or
70      (UpperCase(Value) = 'YES') or (UpperCase(Value) = '.T.') then
71      Result := True
72    else
73      Result := False;
74  end;
75  
76  function BooleanToStr(Value: Boolean): string;
77  begin
78    if Value then
79      Result := 'TRUE'
80    else
81      Result := 'FALSE';
82  end;
83  
84  procedure register;
85  begin
86    RegisterComponents('Data Access', [TBDEConfig]);
87  end;
88  
89  procedure TBDEConfig.Init;
90  var
91    h: hDBICur;
92    pCfgDes: pCFGDesc;
93    n, v: string;
94  begin
95    Check(DbiOpenCfgInfoList(nil, dbiREADWRITE, cfgPersistent, '\SYSTEM\INIT', h));
96    GetMem(pCfgDes, sizeof(CFGDesc));
97    try
98      FillChar(pCfgDes^, sizeof(CFGDesc), #0);
99      while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) = DBIERR_NONE) do
100     begin
101       n := StrPas(pCfgDes^.szNodeName);
102       v := StrPas(pCfgDes^.szValue);
103       if n = 'LOCAL SHARE' then
104         FLocalShare := StrToBoolean(v)
105       else if n = 'MINBUFSIZE' then
106         FMinBufSize := StrToInt(v)
107       else if n = 'MAXBUFSIZE' then
108         FMaxBufSize := StrToInt(v)
109       else if n = 'MAXFILEHANDLES' then
110         FMaxFileHandles := StrToInt(v)
111       else if n = 'LANGDRIVER' then
112         FSystemLangDriver := v
113       else if n = 'AUTO ODBC' then
114         FAutoODBC := StrToBoolean(v)
115       else if n = 'DEFAULT DRIVER' then
116         FDefaultDriver := v;
117     end;
118     if (h <> nil) then
119       DbiCloseCursor(h);
120     Check(DbiOpenCfgInfoList(nil, dbiREADWRITE, cfgPersistent,
121       '\DRIVERS\PARADOX\INIT', h));
122     FillChar(pCfgDes^, sizeof(CFGDesc), #0);
123     while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) = DBIERR_NONE) do
124     begin
125       n := StrPas(pCfgDes^.szNodeName);
126       v := StrPas(pCfgDes^.szValue);
127       if n = 'NET DIR' then
128         FNetFileDir := v
129       else if n = 'LANGDRIVER' then
130         FParadoxLangDriver := v;
131     end;
132     if (h <> nil) then
133       DbiCloseCursor(h);
134     Check(DbiOpenCfgInfoList(nil, dbiREADWRITE, cfgPersistent,
135       '\DRIVERS\PARADOX\TABLE CREATE', h));
136     FillChar(pCfgDes^, sizeof(CFGDesc), #0);
137     while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) = DBIERR_NONE) do
138     begin
139       n := StrPas(pCfgDes^.szNodeName);
140       v := StrPas(pCfgDes^.szValue);
141       if n = 'LEVEL' then
142         FTableLevel := v
143       else if n = 'BLOCK SIZE' then
144         FBlockSize := StrToInt(v)
145       else if n = 'STRICTINTEGRITY' then
146         FStrictIntegrity := StrToBoolean(v);
147     end;
148   finally
149     FreeMem(pCfgDes, sizeof(CFGDesc));
150     if (h <> nil) then
151       DbiCloseCursor(h);
152   end;
153 end;
154 
155 procedure TBDEConfig.SetLocalShare(Value: Boolean);
156 begin
157   UpdateCfgFile('\SYSTEM\INIT', 'LOCAL SHARE', BooleanToStr(Value));
158   FLocalShare := Value;
159 end;
160 
161 procedure TBDEConfig.SetMinBufSize(Value: Integer);
162 begin
163   UpdateCfgFile('\SYSTEM\INIT', 'MINBUFSIZE', IntToStr(Value));
164   FMinBufSize := Value;
165 end;
166 
167 procedure TBDEConfig.SetMaxBufSize(Value: Integer);
168 begin
169   UpdateCfgFile('\SYSTEM\INIT', 'MAXBUFSIZE', IntToStr(Value));
170   FMaxBufSize := Value;
171 end;
172 
173 procedure TBDEConfig.SetSystemLangDriver(Value: string);
174 begin
175   UpdateCfgFile('\SYSTEM\INIT', 'LANGDRIVER', Value);
176   FSystemLangDriver := Value;
177 end;
178 
179 procedure TBDEConfig.SetParadoxLangDriver(Value: string);
180 begin
181   UpdateCfgFile('\DRIVERS\PARADOX\INIT', 'LANGDRIVER', Value);
182   FParadoxLangDriver := Value;
183 end;
184 
185 procedure TBDEConfig.SetMaxFileHandles(Value: Integer);
186 begin
187   UpdateCfgFile('\SYSTEM\INIT', 'MAXFILEHANDLES', IntToStr(Value));
188   FMaxFileHandles := Value;
189 end;
190 
191 procedure TBDEConfig.SetNetFileDir(Value: string);
192 begin
193   UpdateCfgFile('\DRIVERS\PARADOX\INIT', 'NET DIR', Value);
194   FNetFileDir := Value;
195 end;
196 
197 procedure TBDEConfig.SetTableLevel(Value: string);
198 begin
199   UpdateCfgFile('\DRIVERS\PARADOX\TABLE CREATE', 'LEVEL', Value);
200   FTableLevel := Value;
201 end;
202 
203 procedure TBDEConfig.SetBlockSize(Value: Integer);
204 begin
205   UpdateCfgFile('\DRIVERS\PARADOX\TABLE CREATE', 'BLOCK SIZE', IntToStr(Value));
206   FBlockSize := Value;
207 end;
208 
209 procedure TBDEConfig.SetStrictIntegrity(Value: Boolean);
210 begin
211   UpdateCfgFile('\DRIVERS\PARADOX\TABLE CREATE', 'STRICTINTEGRITY',
212     BooleanToStr(Value));
213   FStrictIntegrity := Value;
214 end;
215 
216 procedure TBDEConfig.SetDefaultDriver(Value: string);
217 begin
218   UpdateCfgFile('\SYSTEM\INIT', 'DEFAULT DRIVER', Value);
219   FDefaultDriver := Value;
220 end;
221 
222 procedure TBDEConfig.SetAutoODBC(Value: Boolean);
223 begin
224   UpdateCfgFile('\SYSTEM\INIT', 'AUTO ODBC', BooleanToStr(Value));
225   FAutoODBC := Value;
226 end;
227 
228 procedure TBDEConfig.UpdateCFGFile;
229 var
230   h: hDbiCur;
231   pCfgDes: pCFGDesc;
232   pPath: array[0..127] of char;
233 begin
234   StrPCopy(pPath, Path);
235   Check(DbiOpenCfgInfoList(nil, dbiREADWRITE, cfgPersistent, pPath, h));
236   GetMem(pCfgDes, sizeof(CFGDesc));
237   try
238     FillChar(pCfgDes^, sizeof(CFGDesc), #0);
239     while (DbiGetNextRecord(h, dbiWRITELOCK, pCfgDes, nil) = DBIERR_NONE) do
240     begin
241       if StrPas(pCfgDes^.szNodeName) = item then
242       begin
243         StrPCopy(pCfgDes^.szValue, value);
244         Check(DbiModifyRecord(h, pCfgDes, True));
245       end;
246     end;
247   finally
248     FreeMem(pCfgDes, sizeof(CFGDesc));
249     if (h <> nil) then
250       DbiCloseCursor(h);
251   end;
252 end;
253 
254 constructor TBDEConfig.Create(AOwner: TComponent);
255 begin
256   inherited Create(AOwner);
257   Init;
258 end;
259 
260 destructor TBDEConfig.Destroy;
261 begin
262   inherited Destroy;
263 end;
264 
265 end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC