[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help on typed files

Posted on 1998-09-11
1
Medium Priority
?
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
Motaz earned 100 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

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.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 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