Pascal Notes. Getting started.



Var declaration


var,var,var .... : Type ;

PChar = > Far ptr ( use for win call in API)




GetMem = > malloc

StrPcopy = > Copy String to Pointer

StrCat() => Concatenates

+  => Concatenate strings


FreeMem => free()



Arrays
======
A: Array [1..8] of integer;


int A[8];



Structures
==========
Type
 MyRec= record
i: integer;
d: Double;
end;

accessing a record( structures)
===============================

var N: MyRec
ebgin
N.i = 1000.1
N.d = 333.4


Pointers
========
Pointer is untyped

Declare Pointers

Declare Typed pointers (like C's *)

e.g:

PInt = ^Integer
PMyClass = ^MyClass



e.g

Program PtrTest

Type
MyRec = record
I: integer
s:String
R:Real
End;

PMyRrec = ^MyRec

var
Rec : PMyRec

begin
 New(Rec)  -> allocate c++ new

Rec^.I:= 10; // ^. in pascal  is the same as    ->  in C
rec^.s:='xx';
rec^.R:= 6.384

Dispose (Rec) // free(ptr)

End.













0 comments:

Post a Comment