uses Windows;
type
PTrack = ^TTrack; TTrack = packed record Number: Byte;
Title: string [30];
Artist: string [30];
Album: string [30];
Year: Word;
Comment: string [30];
Genre: Byte;
end;
var
Dummy: Cardinal; Items: packed record Count: Cardinal; Item: array [0..255] of PTrack; end;
function NewItem: PTrack; begin
New(Result); Items.Item[Items.Count] := Result; Inc(Items.Count); end;
function DelItem(Index: Cardinal): LongBool; begin
Result := Index < Items.Count; if not Result then Exit;
Dispose(Items.Item[Index]); while Index < Items.Count do
begin
Items.Item[Index] := Items.Item[Index + 1]; Inc(Index);
end;
Dec(Items.Count); end;
function Save(lpFileName: PChar): LongBool;
var hFile, Index: Cardinal;
begin
hFile := CreateFile(lpFileName, GENERIC_WRITE, 0, nil, CREATE_ALWAYS, 0, 0); Result := hFile <> INVALID_HANDLE_VALUE;
if not Result then Exit;
Index := 0;
WriteFile(hFile, Items.Count, 4, Dummy, nil); while Index < Items.Count do
begin
WriteFile(hFile, Items.Item[Index]^, SizeOf(Items.Item[0]^), Dummy, nil); Inc(Index);
end;
CloseHandle(hFile);
end;
function Open(lpFileName: PChar): LongBool;
var hFile, Index: Cardinal;
begin
hFile := CreateFile(lpFileName, GENERIC_READ, 0, nil, OPEN_EXISTING, 0, 0); Result := hFile <> INVALID_HANDLE_VALUE;
if not Result then Exit;
ReadFile(hFile, Index, 4, Dummy, nil);
while Items.Count < Index do
ReadFile(hFile, NewItem^, SizeOf(Items.Item[0]^), Dummy, nil);
CloseHandle(hFile);
end;
begin
Open('pseudoBD.dat');
if Items.Count >= 4 then
DelItem(0);
with NewItem^ do begin
Number := 1;
Title := 'Allegro Club Delphi';
Artist := 'cHackAll';
Year := 2007;
end;
with NewItem^ do begin
Number := 2;
Title := 'Sinfonía Nº1 Delphiana';
Artist := 'Moderadores';
Year := 2008;
end;
Save('pseudoBD.dat');
end.