Solved

Help on typed files

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 106
find a node in VST 2 73
delphi parse string to params 3 136
Firemonkey BASS_Init into a thread 17 31
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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