Solved

Help on typed files

Posted on 1998-09-11
1
128 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 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