: :
: : hi everyone,
: :
: : i would be really greatefull if anybody can solve these 3 pproblems of mine :
: :
: : 1. I want to make a type in pascal whose size should be only 2 bits, so that there will be only 4 possible values for it(00,01,10,11).
: :
: : 2. Next i want to make an array of this type.
: :
: : 3. The important thing is i want to set the size of the array at runtime.
: :
: : waiting eagerly for replies..thanking in anticipation
: :
: 1) Well probably you can't make a type which consists of 2 bits only. Here is another solution:
:
: type
: My2bit = (b00,b01,b10,b11);
:
:
: 2) Simple:
:
: var
: bitarray=array[1..40] of my2bit; { 1 and 40 can be any other value }
:
:
: 3) Well, at runtime - this is not possible I'm afraid. But, maybe I miunderstood your question, maybe this is what you're looking for:
:
: var
: x:byte;
: bitarray:array[1..x] of my2bit;
:
:
: Hope this help you out. And, sorry for my english.
:
: ****************
: Any questions? Just ask!
:
:
GAASHIUS 
:
:
:
The only 2 ways of creating dynamically memory lists are:
- TMemoryStream (or a descendant of it)
- linked-list
A linked list uses records, where each record consists of at least 2 fields: 1 or more for the data, and 1 for the location of the next record. In your case that would be:
type
PMy2Bits = ^TMy2Bits;
TMy2Bits = record
Bits: My2bit;
Next: PMy2Bits;
end;
This way you can link records together, by only remembering the location of the first record:
var
MyBitsArray: PMy2Bits;
The drawback of this way is that the coding of the navigation quite involved is. For example: to get the indexth 2-bits you need something like this:
function GetBits(index: integer): My2bit;
var
i: integer;
begin
Current := MyBitsArray;
i := 0;
while i < Index do
begin
Current := Current^.Next;
inc(i);
end;
Result := Current^.Bits;
end;
Also each record must be specifically be created using the New() statement.