Solved

Help on typed files

Posted on 1998-09-11
1
123 Views
Last Modified: 2010-04-06
Here is a function I wrote in one of my programs.  Even though there is two records in the data file, this function keeps returning the result of 0 when it should match up to the caller name and it does not?  Any suggestions?

Function IsPlayerNew(TempName: string):integer;
var
  x,y: integer;
Begin
  x:=1;
  IsPlayerNew := 0;
  {$I-}
  ChDir(ProgPath);
  if IOResult <> 0 then
  begin
    msg := 'DMSOFT(137): Can not change do directory specified!';
    Write_Actlog(pbbswin,msg);
  end;
  If FileExists(PlayerFile) then
  begin {file exists}
    Assign(TPlayerFile,PlayerFile);
    ReSet(TPlayerFile);
    y:=FileSize(TPlayerFile);
    Write_ActLog(pbbswin,'Number of Records: '+IntToStr(y);
    While x<>y do
    begin {while}
     try
       If not EOF(TPlayerFile) then
       begin {try}
         Seek(TPlayerFile,X-1);
         PlayerName := Player.pPlayerName;
         If PlayerName<>TrimIt(TempName) then x:=x+1;
         If PlayerName=TrimIt(TempName) then IsPlayerNew := x;
         x:=X+1;
       end; {try}
       finally
         CloseFile(TPlayerFile);
         ChDir(BBSPath);
       end; {finally}
    end; {while}
  end; {file exists}
  CloseFile(TPlayerFile);
  ChDir(BBSPath);
End; {procedure}

Note:  Any code changes that are offerred need to be supported in both 16bit and 32bit Delphi.
0
Comment
Question by:DMM1956
1 Comment
 
LVL 7

Accepted Solution

by:
Motaz earned 50 total points
ID: 1339497
Hello there.
You miss to read the record from the file.
The missing procedure is : Read(TPlayerFile,Player);

This is the corrected code :

Function IsPlayerNew(TempName: string):integer;
var
  x,y: integer;
Begin
  x:=1;
  IsPlayerNew := 0;
  {$I-}
  ChDir(ProgPath);
  if IOResult <> 0 then
  begin
    msg := 'DMSOFT(137): Can not change do directory specified!';
    Write_Actlog(pbbswin,msg);
  end;
  If FileExists(PlayerFile) then
  begin {file exists}
    Assign(TPlayerFile,PlayerFile);
    ReSet(TPlayerFile);
    y:=FileSize(TPlayerFile);
    Write_ActLog(pbbswin,'Number of Records: '+IntToStr(y);
    While x<>y do
    begin {while}
     try
       If not EOF(TPlayerFile) then
       begin {try}
         Seek(TPlayerFile,X-1);
         Read(TPlayerFile,Player);  // Missed procedure
         PlayerName := Player.pPlayerName;
         If PlayerName<>TrimIt(TempName) then x:=x+1;
         If PlayerName=TrimIt(TempName) then IsPlayerNew := x;
         x:=X+1;
       end; {try}
       finally
         CloseFile(TPlayerFile);
         ChDir(BBSPath);
       end; {finally}
    end; {while}
  end; {file exists}
  CloseFile(TPlayerFile);
  ChDir(BBSPath);
End; {procedure}

Motaz from Sudan.
motaz1@yahoo.com

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now