Solved

Help on typed files

Posted on 1998-09-11
1
122 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

11 Experts available now in Live!

Get 1:1 Help Now