Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Creating a game...help

Hey I need to create a game.. Im creating a code cracking game using delphi.

Anyway, I'm already stuck at the Username :P

{click on button}
Welcome.Hide;
Game.Show;
username:=Inputbox('Insert your username!', '' ,'');
//

How do I save the username using a file or record :D

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hey I need to create a game.. Im creating a code cracking game using delphi.
    :
    : Anyway, I'm already stuck at the Username :P
    :
    : {click on button}
    : Welcome.Hide;
    : Game.Show;
    : username:=Inputbox('Insert your username!', '' ,'');
    : //
    :
    : How do I save the username using a file or record :D
    :
    Saving the username in a file:
    [code]
    var
    f: text;
    begin
    AssignFile(f, 'username.save');
    Rewrite(f);
    writeln(f, UserName);
    CloseFile(f);
    end;
    [/code]
    Saving the username in a record:
    [code]
    type
    TUser = record
    Name: string;
    end;

    var
    User: TUser;
    begin
    User.Name := Inputbox('Insert your username!', '' ,'');
    end;
    [/code]
    Help = (Throwable.getStackTrace() == null || SourceCode == null) ? null : getHelp(e, SourceCode);

  • swifty23swifty23 Posts: 2Member
    Ah okay thanks.

    How do I save the username into a text file using FILE. Like Im using a form not console app...
  • zibadianzibadian Posts: 6,349Member
    : Ah okay thanks.
    :
    : How do I save the username into a text file using FILE. Like Im using a form not console app...
    :
    The textfile can also be used in a GUI application. If you still want to use a file variable then you need to code it like this:
    [code]
    var
    f: file;
    i: integer;
    begin
    AssignFile(f, filename);
    Rewrite(f, 1);
    i := Length(UserName);
    BlockWrite(f, i, SizeOf(i)); // Write the length of the string
    BlockWrite(f, UserName[1], i); // Write the string itself
    CloseFile(f);
    end;
    [/code]
    Reading it is also more involved that using a textfile:
    [code]
    var
    f: file;
    i: integer;
    begin
    AssignFile(f, filename);
    Reset(f, 1);
    BlockRead(f, i, SizeOf(i)); // Read the length of the string
    SetLength(UserName, i);
    BlockRead(f, UserName[1], i); // Read the string itself
    CloseFile(f);
    end;
    [/code]



    Help = (Throwable.getStackTrace() == null || SourceCode == null) ? null : getHelp(e, SourceCode);

Sign In or Register to comment.