Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4098
Number of posts: 14002

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

Report
Blank space after access to record field ? Posted by Spike89 on 30 Apr 2011 at 12:35 PM
Can anyone please help me understand this part of the code
unit lab5un;
interface
uses LAB5IO;
type MyRec= record
      name1 : STR39;
      name2 : STR39;
      end;
type Myfiletype = file of MyRec;
var MyFileERR :integer;
procedure Fcreate(var fff:Myfiletype; filename:string; var FileOpen: boolean);
procedure Fopenf ( var fff:Myfiletype;filename:string; var FileOpen:boolean);
procedure Fview  ( var fff:Myfiletype; FileOpen: boolean);
procedure FRwRec ( var fff:Myfiletype; FileOpen: boolean);
procedure FClose ( var fff:Myfiletype; var FileOpen: boolean);

implementation
uses CRT;
procedure Fcreate(var fff:Myfiletype; filename:string; var FileOpen: boolean);
var RC, n, i: integer;
    answer : string[1];
    rec :MyRec;
label BUILD;
begin
assign(fff, filename);
{$I-}
RC:=13;
reset(fff);
{$I+}
RC:=ioresult;
if (RC=0) then
      if (FileRewr(filename) = FALSE) then
          begin
          close(fff);
          FileOpen:=False;
          MyFileErr:=1;
          exit;
          end;

{$I-}
rewrite(fff);
{$I+}
     if(IOResult<>0) then begin
                          MyFileErr:=3;
                          FileOpen:=False;
                          exit;
                          end;
       n:=NumOfRec;

       Rec.Name1:='                                              ';
       Rec.Name2:='                                              ';
       for i:=0 to n do
       begin
        Rec.name1:= chr($61 +i);
        Rec.name2:= chr($30 +i);
        write(fff,Rec);
       end;
close(fff);
          FileOpen:=False;
end;


in particular this part
Rec.Name1:='                                              ';
Rec.Name2:='                                             ';

i understand that rec.name gives acces to information in records name1 field but why is there :=' '; after its puzzling me
Report
Re: Blank space after access to record field ? Posted by ROCK_ on 30 Apr 2011 at 11:55 PM
':=' is used to assign value into variable/ record.....its same like assigning value into variable...e.g
var num : integer;
num:= 10;

in above example u r assigning value 10 to variable..in similar way we assign vale to record...imagine record like a field, where u can assign different values in different field....but u have to tell the location where u wanna store the vale

Myrec.name1:='Peter';

this says that u r storing peter into name1(which accepts string) and its a record type.




 

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.