Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.pascal.delphi.databases > #26

Re: How to use function SQLGetPrivateProfileString? Or an alternative?

X-Received by 10.200.51.239 with SMTP id d44mr6925497qtb.12.1468425296107; Wed, 13 Jul 2016 08:54:56 -0700 (PDT)
X-Received by 10.157.2.232 with SMTP id 95mr270228otl.9.1468425295981; Wed, 13 Jul 2016 08:54:55 -0700 (PDT)
Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!j37no1216244qta.0!news-out.google.com!d68ni6469ith.0!nntp.google.com!jk6no22119804igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.pascal.delphi.databases
Date Wed, 13 Jul 2016 08:54:55 -0700 (PDT)
In-Reply-To <4f3934ca-1919-4142-8b01-b585cde960b8@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=137.224.252.10; posting-account=C4I12QgAAABjbGQQImGEEnLbd8rkp6kY
NNTP-Posting-Host 137.224.252.10
References <4f3934ca-1919-4142-8b01-b585cde960b8@googlegroups.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <149d960a-900a-4c4c-bbab-adff64604786@googlegroups.com> (permalink)
Subject Re: How to use function SQLGetPrivateProfileString? Or an alternative?
From dobedani@gmx.net
Injection-Date Wed, 13 Jul 2016 15:54:56 +0000
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Received-Bytes 3134
X-Received-Body-CRC 1317290148
Xref csiph.com comp.lang.pascal.delphi.databases:26

Show key headers only | View raw


On Wednesday, July 13, 2016 at 4:30:09 PM UTC+2, dobe...@gmx.net wrote:
> Dear All,
> I found this thread http://www.delphigroups.info/2/ad/345347.html dating back to the year 2004. It shows how to retrieve a list of DSN entries without poking into the registry directly. So far no problem with Delphi. BTW, I'm using version 2007 on Windows 7. Now I'd like to select only the entries which refer to an MS Access database, so I tried to add only a few lines to the example.
> 
> First I declared this:
> function SQLGetPrivateProfileString(
>   lpszSection, lpszEntry, lpszDefault, lpszRetBuffer: PChar;
>   cbRetBuffer: Integer;
>   lpszFilename: PChar): integer; stdcall;
> 
> and under implementation:
> function SQLGetPrivateProfileString; external 'odbccp32.dll' name 'SQLGetPrivateProfileString';
> 
> Then I added the following line somewhere in the middle of the example: 
> Result := SQLGetPrivateProfileString('ODBC Data Sources', Buffer1, 'Driver', RetBuf, 100, 'odbc.ini');
> 
> with RetBuf also declared as PChar. I was able to retrieve the Driver strings as shown in the registry under ODBC. Unfortunately, the memory is not cleaned up and at the end of it all and execution stops because of this exception: Access violation ...
> 
> I tried to handle this exception but failed. What am I doing wrong? I tried running the code also as Administrator but saw no difference. Any help will be appreciated!

Dear All,
It appeared to be a simple problem: initialising the PChar variable RetBuf and later on freeing it, solved the problem of the access violations: 
GetMem(RetBuf, 100);
...
FreeMem(RetBuf);

My next question is now: how to retrieve the path to the *. MDB file involved (or *.ACCDB file). I tried this, but to no avail:
SQLGetPrivateProfileString('', Buffer1, 'DBQ', RetBuf, 128, 'odbc.ini')

Any help will be appreciated ...

Back to comp.lang.pascal.delphi.databases | Previous | NextPrevious in thread | Find similar


Thread

How to use function SQLGetPrivateProfileString? Or an alternative? dobedani@gmx.net - 2016-07-13 07:30 -0700
  Re: How to use function SQLGetPrivateProfileString? Or an alternative? dobedani@gmx.net - 2016-07-13 08:54 -0700

csiph-web