Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Program Record Posted by m0rTaL on 19 Jun 2009 at 1:32 PM
Hey, I seem to have a few problems
1. I want to use Records ex.
User=Record
           Username: string;
           Password: string;

Now if I want to compare one of those with a string it doesnt work ex.
User.Username = TEMP

it will give me an error ''Operator is not overloaded''
Why can't it compare the two variables?

2. How can I write an array into a string or read out an array to compare the single cells with a variable? Like the cell 1 of the array is equal to a sring? Here an example that I made that doesnt work
Example[1] = TEMP
if I try that it will not work because it says cant read or write from this type of Variable

Can somebody help me there? Thx a lot in Advance
Report
Re: Program Record Posted by Actor on 19 Jun 2009 at 4:02 PM
You need to post more of your code. There's not enough here to tell what is happening.

Report
Re: Program Record Posted by Actor on 19 Jun 2009 at 4:04 PM
You need to post more of your code. There's not enough here to tell what is happening.

Report
Re: Program Record Posted by m0rTaL on 19 Jun 2009 at 4:13 PM
Here is my Code

program User_Registration;

uses
  Crt;

Type
    Userrecord= Record
          Password: string;
          Username: string;
          Password_ID: integer;
          Username_ID: integer;
end;

Var

   Index: integer;
   Temp: string;
   I: integer;
   n: integer;
   Database: array [0..100] of string;
   User: Userrecord;


Begin



                Index:=0;
                randomize;
                writeln('User Registration Area');
                writeln('');
                writeln('');
                                                {Eingabe des Usernamen}
                write('Username: ');
                readln(Userrecord.Username);
                                                {überprüfung ob der Username bereits existiert}
                for I:= 1 to 100 do
                    begin
                         if Userrecord.Username = 'Database[0..100]' then
                            begin
                                 repeat
                                       begin
                                            write('Username: ');
                                            readln(Userrecord.Username);
                                       end;
                                 until Userrecord.Username <> 'Database[0..100]';
                            end;
                    end;
                Index:=Index+1;
                Database[Index]:=Userrecord.Username;


                                                {Eingabe des Passworts}
     write('Password: ');
     readln(Userrecord.Password);
     writeln('');
                                                {Konfirmation des Passworts}
     write('Please confirm Password: ');
     readln(TEMP);
                                                 {überprüfung des Passwortes}
     if Userrecord.Password <> Temp then
        begin
             writeln(' Password doesnt match Confirmation');
             writeln('');
                         repeat
                               begin
                                    write('Password: ');
                                    readln(Userrecord.Password);
                                    writeln('');
                                    write('Please confirm Password: ');
                                    readln(TEMP);
                               end;
                         until Userrecord.Password = Temp;
        end;
        for I:= 1 to 100 do
        writeln('Database[0..Index]');
                                                 {Zuweisung einer Identifikationsnummer}
end. 

Report
Re: Program Record Posted by Actor on 19 Jun 2009 at 6:59 PM
: Here is my Code
:
:
: program User_Registration;
: 
: uses
:   Crt;
: 
: Type
:     Userrecord= Record
:           Password: string;
:           Username: string;
:           Password_ID: integer;
:           Username_ID: integer;
: end;
: 
: Var
: 
:    Index: integer;
:    Temp: string;
:    I: integer;
:    n: integer;
:    Database: array [0..100] of string;
:    User: Userrecord;
: 
: 
: Begin
: 
: 
: 
:                 Index:=0;
:                 randomize;
:                 writeln('User Registration Area');
:                 writeln('');
:                 writeln('');
:                                                 {Eingabe des Usernamen}
:                 write('Username: ');
:                 readln(Userrecord.Username);
                  {
                      Userrecord is a type, not a variable.
                      Use User instead of Userrecord 
                  }
:                                                 {überprüfung ob der Username bereits existiert}
:                 for I:= 1 to 100 do
:                     begin
:                          if Userrecord.Username = 'Database[0..100]' then
:                             begin
:                                  repeat
:                                        begin
:                                             write('Username: ');
:                                             readln(Userrecord.Username);
:                                        end;
:                                  until Userrecord.Username <> 'Database[0..100]';
:                             end;
:                     end;
:                 Index:=Index+1;
:                 Database[Index]:=Userrecord.Username;
: 
: 
:                                                 {Eingabe des Passworts}
:      write('Password: ');
:      readln(Userrecord.Password);
:      writeln('');
:                                                 {Konfirmation des Passworts}
:      write('Please confirm Password: ');
:      readln(TEMP);
:                                                  {überprüfung des Passwortes}
:      if Userrecord.Password <> Temp then
:         begin
:              writeln(' Password doesnt match Confirmation');
:              writeln('');
:                          repeat
:                                begin
:                                     write('Password: ');
:                                     readln(Userrecord.Password);
:                                     writeln('');
:                                     write('Please confirm Password: ');
:                                     readln(TEMP);
:                                end;
:                          until Userrecord.Password = Temp;
:         end;
:         for I:= 1 to 100 do
:         writeln('Database[0..Index]');
:                                                  {Zuweisung einer Identifikationsnummer}
: end. 
:
:

By the way, begin .. end is not necessary inside repeat .. until.
Report
Re: Program Record Posted by Phat Nat on 19 Jun 2009 at 7:00 PM
: Here is my Code
:
:
: program User_Registration;
: 
: uses
:   Crt;
: 
: Type
:     Userrecord= Record
:           Password: string;
:           Username: string;
:           Password_ID: integer;
:           Username_ID: integer;
: end;
: 
: Var
: 
:    Index: integer;
:    Temp: string;
:    I: integer;
:    n: integer;
:    Database: array [0..100] of string;
:    User: Userrecord;
: 
: 
: Begin
: 
: 
: 
:                 Index:=0;
:                 randomize;
:                 writeln('User Registration Area');
:                 writeln('');
:                 writeln('');
:                                                 {Eingabe des Usernamen}
:                 write('Username: ');
:                 readln(Userrecord.Username);
:                                                 {überprüfung ob der Username bereits existiert}


You declare userrecord as User, but then don't use it. You need to change all your record pointer names from "userrecord" to "User"
readln(User.Username);


I haven't checked the rest of the code thouroughly, but try this first.
Report
Re: Program Record Posted by m0rTaL on 20 Jun 2009 at 1:35 AM
Oh right I took out the begin end in the repeat until really wasnt needed. But when I change the readln userrecord.username into User.Username and try to read or write it will give an error that the variable isnt allowed. How can I have a record and read and write it? =/
Report
Re: Program Record Posted by Actor on 20 Jun 2009 at 7:10 PM
I get no errors. This works as far as getting the password.
program User_Registration;

uses
  Crt;

Type
   Userrecord = Record
      Password    : string;
      Username    : string;
      Password_ID : integer;
      Username_ID : integer;
   end;

Var
   Index    : integer;
   Temp     : string;
   I        : integer;
   n        : integer;
   Database : array [0..100] of string;
   User     : Userrecord;

Begin
   Index:=0;
   randomize;
   writeln('User Registration Area');
   writeln('');
   writeln('');
   { Eingabe des Usernamen }
   write('Username: ');
   readln(User.Username);
                                                
   { überprüfung ob der Username bereits existiert }
   for I:= 1 to 100 do begin
      if User.Username = 'Database[0..100]' then begin
         repeat
            write('Username: ');
            readln(User.Username)
         until User.Username <> 'Database[0..100]';
      end;
   end;
   Index:=Index+1;
   Database[Index]:=User.Username;
                                                
   { Eingabe des Passworts }
   write('Password: ');
   readln(User.Password);
   writeln('');
                                                
   { Konfirmation des Passworts }
   write('Please confirm Password: ');
   readln(TEMP);
                                                 
   {überprüfung des Passwortes}
   if User.Password <> Temp then begin
      writeln(' Password doesnt match Confirmation');
      writeln('');
      repeat
         
         write('Password: ');
                                             
         readln(User.Password);
         writeln('');
         write('Please confirm Password: ');
         readln(TEMP);
      until User.Password = Temp;
   end;
   for I:= 1 to 100 do
        writeln('Database[0..Index]');
   {  Zuweisung einer Identifikationsnummer  }
end.

Which implementation of Pascal are you using?

Try this.
   with User do
      readln(Username);

Or this.
   for j := 1 to Length(User.Username) do
      read(User.Username[j]);
   readln

or a combination.
   with User do
      for j := 1 to Length(UserName) do
         read(UserName[j]
      readln ;


Report
Re: Program Record Posted by m0rTaL on 22 Jun 2009 at 8:10 AM
Thx a lot for the Help, now my prog works :D

I used Lazarus IDE which uses FreePascal
Now I use Turbo Pascal 7.0 and it works, how is that possible, does the FreePascal use a different Implementation? Oo
Report
Re: Program Record Posted by Atex on 22 Jun 2009 at 5:03 PM
: I used Lazarus IDE which uses FreePascal
: Now I use Turbo Pascal 7.0 and it works, how is that possible, does
: the FreePascal use a different Implementation? Oo
:

FP has multiple modes, by default is not TP7 or Delphi compatible, so a program written in these dialects will not necessarily compile, unless you use the {$mode ...} directive ( for TP7 use {$mode tp} ) to change the compatibility of the compiler. Read FP's documentation for more info, is well written and quite extensive.

Report
Re: Program Record Posted by m0rTaL on 23 Jun 2009 at 3:51 AM
Ah so it is the Information that is always on top of the program when you create a new one in Lazarus?

I always deleted those informations ^^ Guess that must be the reason, thx for the great help =)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.