Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Win 98 problem with get Dir & ini files

Posted on 2000-02-25
15
Medium Priority
?
222 Views
Last Modified: 2010-04-04
In delphi 4 I use the following code to run a program when a button is pressed, svnewspath is read from an ini file using Tinifile.readstring.

On windows 95, NT4 and 2000 it works fine but on all the 98 machines I've tried it just gives a "sorry file not found: d:\\" error.

Wht is 98 neither handling the string from the ini file or the getDir funcion.

procedure TForm1.SBtnNewsClick(Sender: TObject);
Var
  Dir, Path : String;
begin
  GetDir(0,Dir);
  Path := Dir+'\'+svNewsPath;
  if FileExists(Path) then
    begin
    ChDir(extractFilePath(Path));
    WinExec(Pchar(Path),SW_MAXIMIZE);
    ChDir(Dir);
    end
  else
    ShowMessage('Sorry, File not found:'+Path);

end;
0
Comment
Question by:mike_tipping
  • 5
  • 5
  • 2
  • +3
15 Comments
 
LVL 3

Expert Comment

by:ckaneta
ID: 2558438
Maybe you have an extra backslash in the path.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2558456
GetDir is a tricky one - I never know if it includes a '\' or not so just modify your code so that it reads:

GetDir(0, Path);
IF Path[Length(Path)] <> '\'
THEN
  Path := Path + '\';
Path := Path + svNewPath;
IF FileExists...

By the way, if you're trying to find out if a path exists or not, try this routine:

FUNCTION PathExists(sPath : STRING): BOOLEAN;
  VAR
    srcFile   : TSearchRec;
    sSubPath  : STRING;
    bFinished : BOOLEAN;
    iCount    : INTEGER;
  BEGIN
    Result := FALSE;
    IF sPath = ''
    THEN
      Exit;

    IF sPath[Length(sPath)] = '\'
    THEN
      SPath := Copy(sPath, 1, Length(sPath) - 1);

    sSubPath := '';
    iCount := Length(sPath);
    REPEAT
      bFinished := FALSE;
      IF sPath[iCount] = '\'
      THEN
        bFinished := TRUE
      ELSE
      BEGIN
        sSubPath := sPath[iCount] + sSubPath;
        iCount := iCount - 1;
      END;
    UNTIL bFinished OR (iCount = 0);

    sSubPath := UpperCase(TRIM(sSubPath));
    IF FindFirst(sPath, faDirectory, srcFile) = 0
    THEN
    BEGIN
      IF UpperCase(TRIM(srcFile.Name)) = sSubPath
      THEN
        Result := TRUE
      ELSE
        WHILE FindNext(srcFile) = 0
        DO
          IF UpperCase(TRIM(srcFile.Name)) = sSubPath
          THEN
            Result := TRUE;
      FindClose(srcFile);
    END;
  END;


The Neil
0
 

Author Comment

by:mike_tipping
ID: 2558498
It seems to be a thing with 98 not the code, I'm wondering if 98 is doing somthing strange as the code works on NT, 2000 and 95
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Expert Comment

by:TheNeil
ID: 2558521
As I said, it could be a quirk in GetDir. Have you checked the value of Path before you do the FileExists?

The Neil
0
 

Author Comment

by:mike_tipping
ID: 2558576
This apparently only happens when the exe is run from a CD, run it from the HD and it's fine. Run it from the CD on 95, NT and 200 and it's fine...

0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2558604
According to the Delphi help, GetDir will return a valid path even if the drive doesn't exist. Might it be worthwhile checking to see if the drive exists before you do the GetDir? I still think that it's something to do with the creation of the path string

The Neil
0
 

Author Comment

by:mike_tipping
ID: 2558675
I don't think it's a problem with get dir, thinking about it the error message says file d:\\ doesn't exist and since its from a CD the drive letter seems to be picked up fine, it seems to be the ini file reading which ias at fault, code is below, but why would an ini file be read ok everywhere but on a CD under 98?

procedure TForm1.FormActivate(Sender: TObject);
Var
  UDLName : array[0..255] of char;
  LangSection : String;
  LingoIni : TIniFile;
  Dir : String;
begin
  GetDir(0,Dir);
  LingoIni := TInifile.Create(Dir+'\Lingo.ini');
  svNewsPath := Lingoini.readString('setups','News','');
  svRoutePath := Lingoini.readString('Setups','Route','');
  svMapPath := Lingoini.readString('Setups','Maps','');
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2559760
What happens when you use GetCurrentDir instead of GetDir?
0
 
LVL 20

Accepted Solution

by:
Madshi earned 160 total points
ID: 2560555
Why do you use GetDir at all? Perhaps you want to get the path where your application was started from? Then you should use ExtractFilePath(ParamStr(0)). Please tell us more about what your code is supposed to do.

BTW, you should not use WinExec, instead you should use ShellExecute, there you can give in a default directory for the new process, so you don't need this ChDir stuff before and after WinExec. I even don't know if your ChDir before WinExec has any effect on WinExec.

Regards, Madshi.
0
 

Author Comment

by:mike_tipping
ID: 2564160
The program is basically a CD front end that runs variouse install routines. The paths and buttons images for these routines are set up with an ini file. I run Get Dir to find where I am at the time that add the path from the ini file onto that to get the location of the install exe I'm going to run.

I take your point that GetDir isn't the best thing to use and shell execute would be better that WinExec but the problem isn't with this, Looking at the error message I get back the Directory has been retrieved (D:\ is the root of the CD rom), it's the inhi file that isn't being read properly.

As I say this is a 98 only problem and only on a CD, works find on HD.

Any ideas?
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 2564735
i had the same problem
my program worked on the harddisk
but failed to work after being burned on a cd

the reason is that getdir has two "modes"
if you are in a subdirectory you'll get:
F:\development\test

if you are in the root of a directory you'll get
F:\

and thats the reason you get d:\\
because your file is in the root of the cd

if you load an image with
  GetDir(0,Dir);
  image1.picture.loadfromfile(dir+'//test.jpg');
or
  GetDir(0,Dir);
  image1.picture.loadfromfile(dir+'\\test.jpg');
it works !!! --tested under d5 and win98se

but only on a fixed disk and not on a cd
(i think its the cd-filesystem)

you should accept TheNeil's answer
my solution to the problem looks nearly the same

regards
fred
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2564765
Thanks Fred,

This was the point I was trying to get across (badly as it turns outason I put in checks to look for trailing '\' characters

The Neil
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2564872
Oops, must swicth overwrite OFF. What I meant to say (before screwing it all up) was that this was the reason WHY I kept checking for trailing '\' characters

The Neil
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 2565031
8-)
0
 

Author Comment

by:mike_tipping
ID: 2580465
I don't think it was the answer to the problem but the code was usefull to make the solution I came up with work properly. Ititialy I try to read the ini file from the CD if I can't (win98) I copy the ini file into the systems temp diretory and read it from there.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question