LoadArray example for Delphi
procedure TForm1.LoadArrayClick(Sender: TObject);
var
i: Smallint;
Buffer: Variant;
MyBufferPtr: Pointer;
BytesRead: Longint;
FileHandle: integer;
RasterVarBuffer: LEADRasterVariant;
RasterIO: LEADRasterIO;
begin
RasterIO:= CoLEADRasterIO.Create ();
RasterVarBuffer:= CoLEADRasterVariant.Create ( );
Buffer:= VarArrayCreate([0, 40000-1], varByte);
MyBufferPtr := AllocMem(40000);
FileHandle := FileOpen('c:\babe.cmp', fmOpenRead );
if (FileHandle > 0) then
begin
BytesRead := FileRead(FileHandle, MyBufferPtr^, 40000); // read from the file
for i:= 0 to BytesRead-1 do
Buffer[i] := Byte((Pchar(MyBufferPtr)+i)^);
RasterVarBuffer.StringValue:= Buffer;
RasterIO.LoadArray(LEADRasterView1.Raster, RasterVarBuffer, 0, 1, 1, BytesRead);
end;
FreeMem(MyBufferPtr);
FileClose( FileHandle );
end;