whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

33 Visitors Online


 
...Save and load a 2-dimensional dynamic array?
Autor: P. Below
[ Print tip ]  

Tip Rating (10):  
     



type
  
T2DBooleanArray = array of array of Boolean;

procedure Save2DBooleanArray(const A: T2DBooleanArray; S: TStream);
var
  
writer: TWriter;
  i: Integer;
begin
  
Assert(Assigned(S));
  writer := TWriter.Create(S, 8096);
  try
    
writer.WriteInteger(Length(A));
    for i := 0 to Length(A) - 1 do
    begin
      
writer.WriteInteger(Length(A[i]));
      writer.Write(A[i, 0], Length(A[i]) * sizeof(A[i, 0]));
    end{ For }
  
finally
    
writer.Free;
  end{ Finally }
end;

procedure Load2DBooleanArray(var A: T2DBooleanArray; S: TStream);
var
  
reader: TReader;
  i, numrows, numcols: Integer;
begin
  
Assert(Assigned(S));
  reader := TReader.Create(S, 8096);
  try
    
numrows := reader.ReadInteger;
    SetLength(A, numrows);
    for i := 0 to numrows - 1 do
    begin
      
numcols := reader.ReadInteger;
      SetLength(A[i], numcols);
      reader.Read(A[i, 0], numcols * sizeof(A[i, 0]));
    end{ For }
  
finally
    
reader.Free;
  end{ Finally }
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners