Ver la Versión Completa : Guardar un type packed record
Mike Deet
18-01-2008, 16:46:59
Ola
eu tenho um type que é um packed record de RGB e tenho um array desse type, eu queria guardar esse array num ficheiro e depois abrir esse ficheiro e guardar no mesmo array.
Type
TCubo=packed record
B,G,R:byte;
end;
CuboRGB:array[0..255,0..255,0..255] of TCubo;
algue me diz umas dicas como fazer isto.
MUCHAS GRACIAS
Crandel
18-01-2008, 18:43:40
Hola Mike, aprende el uso etiquetas para tu codigo sea mas legible.
La idea es crear un archivo del tipo TCubo, el codigo seria algo asi:
var
Archi: file of TCubo;
i,j,k: integer;
begin
AssignFile(Archi, 'nombre.dat');
Rewrite(Archi);
for i := 0 to 255 do
for j := 0 to 255 do
for k := 0 to 255 do
Write(Archi, CuboRGB[i,j,k]);
CloseFile(Archi);
end;
Suerte
jachguate
18-01-2008, 21:07:05
También se puede hacer con un stream:
type
TColorRGB = packed record
B, G, R: byte;
end;
TCuboRGB = array[0..255,0..255,0..255] of TColorRGB;
procedure GuardaCubo(const CuboRGB: TCuboRGB);
var
Arch: TFileStream;
begin
Arch := TFileStream.Create('c:\datos.dat', fmCreate or fmShareExclusive);
try
if Arch.Write(CuboRGB, SizeOf(CuboRGB)) <> SizeOf(CuboRGB) then
raise Exception.Create('Error al escribir!');
finally
Arch.Free;
end;
end;
procedure LeeCubo(var CuboRGB: TCuboRGB);
var
Arch: TFileStream;
begin
Arch := TFileStream.Create('c:\datos.dat', fmOpenRead or fmShareDenyNone);
try
if Arch.Read(CuboRGB, SizeOf(CuboRGB)) <> SizeOf(CuboRGB) then
raise Exception.Create('Error al leer!');
finally
Arch.Free;
end;
end;
Hasta luego.
;)
Crandel
18-01-2008, 21:49:03
También se puede hacer con un stream:
sisi, me quedaría con tu solución
vBulletin v3.6.8, Derechos ©2000-2024, Jelsoft Enterprises Ltd.