diff --git a/simple_examples/simple_expressions.pas b/simple_examples/simple_expressions.pas new file mode 100644 index 0000000..121559b --- /dev/null +++ b/simple_examples/simple_expressions.pas @@ -0,0 +1,18 @@ +program simple_expressions; + +{$mode objfpc}{$H+} + +var + b: Byte = 4; + c: Byte = 3; + +begin + WriteLn('Initial value of b is ', b, '; initial value of c is ', c, sLineBreak); + b := b shr 1; // >> shift right + c := shl 4; // << shift left + WriteLn('After b shr 1, b is ', b, '; after c shl 4, c is ', c, sLineBreak); + WriteLn('c xor b = ',c xor b, '; c and b = ', c and b, '; c or b,' + {$IFDEF WINDOWS} + ReadLn; + {$ENDIF} +end. \ No newline at end of file diff --git a/text_file/text_file.lpi b/text_file/text_file.lpi new file mode 100644 index 0000000..bdf9e20 --- /dev/null +++ b/text_file/text_file.lpi @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + <UseAppBundle Value="False"/> + <ResourceType Value="res"/> + </General> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + <UseFileFilters Value="True"/> + </PublishOptions> + <RunParams> + <FormatVersion Value="2"/> + <Modes Count="0"/> + </RunParams> + <Units Count="1"> + <Unit0> + <Filename Value="text_file.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <Target> + <Filename Value="text_file"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/text_file/text_file.lpr b/text_file/text_file.lpr new file mode 100644 index 0000000..e332f86 --- /dev/null +++ b/text_file/text_file.lpr @@ -0,0 +1,47 @@ +program text_file; + +{$mode objfpc}{$H+} + +uses sysutils; + +var + txtF: TextFile; + s: String; + +procedure ReadTenLines; +const lineNo: integer = 0; +var linesRead: integer = 0; +begin + while not EOF(txtF) and (linesRead < 10) do + begin + ReadLn(txtF, s); // Read the current line in the file, and store in s + Inc(linesRead); // linesRead += 1 + Inc(lineNo); + s := Format('Line %d: %s', [lineNo, s]); + WriteLn(s); + end; +end; + +begin + AssignFile(txtF, 'text_file.lpr'); // Open pointer to the file + Reset(txtF); // Open existing file + WriteLn('Lines from text_file.lpr will be displayed 10 at a time'); + WriteLn; + + // Read and display the file + try + while not EOF(txtF) do + begin + ReadTenLines; + WriteLn; + WriteLn('Press [Enter] to continue'); + ReadLn; + end; + finally + CloseFile(txtF); + end; + + Write('End of file reached. Press [Enter] to finish'); + ReadLn; +end. +