Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-08-2001, 02:10 PM
w0rd-driven w0rd-driven is offline
Member
 
Join Date: Jun 2001
Posts: 70
Default BDE API Question

I was wondering if anyone knew a simple way to get a property of a BDE Alias. I don't need to connect to the database, I don't even need it initialized. All I need is for it to read an Interbase servername which is basically the filepath to the .gdb file.

Basically I would like to read say "CompanyDatabase" then get the property name SERVERNAME which could be "C:\Database\Newdb.gdb" or somewhere else. I was then going to overwrite that file with my generic one I made.
I was thinking of calling this using the OnCreate event of a form. Then this form shows the progress of the update, and allows the user to be able to close the window once it's complete. It's really simple, the only thing I'm missing is the BDE code. I can connect to the database no problem using the VCL components. I don't need to connect, all I need are the properties. Connecting would be bad anyways, because I'm overwriting the database I would be connecting to.

I was thinking of parsing through IDEAPI32.cfg but it could be in different locations per computer.

Thanks,
Jeremy
Reply With Quote
  #2  
Old 06-08-2001, 04:44 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: BDE API Question

hi jeremy, try the following code, unfortunately, this function uses BDE, but good news is that BDE will be closed after the return of the fuction, so you should not worry about overwritting anything. btw, this code is simpler and much straigthforward then using VCL components.

function GetDirectory(dbName: String);
var
Dir: String;
DrvDesc : DRVType;
hdb: hDbiDb;
begin
DbiInit(nil);
SetLength(Dir, dbiMaxPathLen + 1);
Check(DbiOpenDatabase(PChar(DbName), nil, dbiReadWrite, dbiOpenShared,
nil, 0, nil, nil, hdb));
Check(DbiGetDirectory(hDB, False, PChar(Dir)));
Check(dbiclosedatabase(hdb));
SetLength(Dir, StrLen(PChar(Dir)));
DbiExit;
Result:= Dir;
end;
Reply With Quote
  #3  
Old 06-18-2001, 09:29 AM
w0rd-driven w0rd-driven is offline
Member
 
Join Date: Jun 2001
Posts: 70
Default RE: BDE API Question

I couldn't get it to work for some reason. I could be applying the code wrong. I made a procedure for the OnCreate event of the form to do most of the calling of that function. I'll be truthful though, this program is to delete a database. We run a program called SalesLogix, basically a spiced up contact manager that uses InterBase. I need a quick thing I can run remotely to wipe it out, we make a Alias called SalesLogix with a Interbase BDE pointer to the database. Basically the BDE Servername string/variable whatever points to say C:\SLXData\yourname.gdb it's different for everyone which makes it a little bit harder to just remove things. Some databases are in different locations, so if I could just somehow access the servername part easily I'd be in business. I know pascal but delphi is super new to me, so It's a little different technique or maybe mine's just a little rusty. I get the GetDirectory function. I'm just wondering what DbName is. Is it the physical location of the database itself? Or the BDE alias? Quicker would be bde alias, it's ALWAYS one word no having to guess through trial and error. Also if I wanted to be super sloppy I could parse through C:\Program Files\BDE\idecfg32.cfg or something. It's a binary file its in there in plain text. Finding the correct text pattern to look for is the hard part. Could be a couple of things. From what I saw of VCL it wants to open the database somewhat permantently it looks like or requires you to login etc. If someone has to type in their password it's very suspicious, and I want this so inconspicuous no one knows its happening until its too late. Remote laptops can get copied super easily so I'm putting more protection on there just right now this old system is needing some self management. I got the right idea, the wrong execution.

OK I'll tell my errors now.
[Error] SLXUpgrade.pas(36): Undeclared identifier: 'DRVType'
[Error] SLXUpgrade.pas(37): Undeclared identifier: 'hDbiDb'
[Error] SLXUpgrade.pas(39): Undeclared identifier: 'DbiInit'
[Error] SLXUpgrade.pas(40): Undeclared identifier: 'dbiMaxPathLen'
[Error] SLXUpgrade.pas(41): Undeclared identifier: 'DbiOpenDatabase'
[Error] SLXUpgrade.pas(41): Undeclared identifier: 'dbiReadWrite'
[Error] SLXUpgrade.pas(41): Undeclared identifier: 'dbiOpenShared'
[Error] SLXUpgrade.pas(43): Undeclared identifier: 'DbiGetDirectory'
[Error] SLXUpgrade.pas(44): Undeclared identifier: 'dbiclosedatabase'
[Error] SLXUpgrade.pas(46): Undeclared identifier: 'DbiExit'
[Error] SLXUpgrade.pas(67): Undeclared identifier: 'dbName'
[Error] SLXUpgrade.pas(67): Illegal character in input file: '"' ($22)
[Error] SLXUpgrade.pas(23): Unsatisfied forward or external declaration: 'TSLXUpdate.GetDirectory'
[Fatal Error] SalesLogixUpdate.dpr(5): Could not compile used unit 'SLXUpgrade.pas'

Here's what I made the function you gave:
function GetDirectory(dbName: String): String;
var
Dir: String;
DrvDesc : DRVType;
hdb: hDbiDb;
begin
DbiInit(nil);
SetLength(Dir, dbiMaxPathLen + 1);
Check(DbiOpenDatabase(PChar(DbName), nil, dbiReadWrite, dbiOpenShared,
nil, 0, nil, nil, hdb));
Check(DbiGetDirectory(hDB, False, PChar(Dir)));
Check(dbiclosedatabase(hdb));
SetLength(Dir, StrLen(PChar(Dir)));
DbiExit;
Result:= Dir;
end;

Then I declared it as:
function GetDirectory(dbName: String): String;

I put this above the other procedures. They have Sender: TObject in the params list, so I just used the function like you said I guess. Did I apply it wrong? Or is this just wrong for me altogether. Thanks for the help sorry it took so long I been busy with other projects to finish this one. Didn't totally think I'd need it.
Reply With Quote
  #4  
Old 06-18-2001, 10:17 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: RE: BDE API Question

put db, bde, dbtables in your uses clause:

uses windows, ....... db, bde, dbtables;

TSLXUpdate = class(TForm)..
...
protected:
function GetDirectory(.....): string;
....
end;

implementation


function TSLXUpdate.GetDirectory(...): string;
begin
...
end;

and yes dbName is alias name and you are not required to login so you can inconspicuously delete it :-)

good luck.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 06:04 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.