Napisałem sobie bibliotekę, aby ułatwić sobie zycie i nie wklejać tych samych procedur do kazdego programu gdzie używam listview, napisałem naciskam f9 i nic tylko kilkanaście błędów
<font size="1">[Error] sllistview.dpr(9): '=' expected but ':' found
[Error] sllistview.dpr(13): Statement expected but 'PROCEDURE' found
[Error] sllistview.dpr(46): Undeclared identifier: 'Items'
[Error] sllistview.dpr(50): 'DO' expected but identifier 'Add' found
[Error] sllistview.dpr(56): Undeclared identifier: 'ImageIndex'
[Error] sllistview.dpr(63): Undeclared identifier: 'Caption'
[Error] sllistview.dpr(75): Missing operator or semicolon
[Error] sllistview.dpr(107): Undeclared identifier: 'Items'
[Error] sllistview.dpr(114): 'THEN' expected but identifier 'Count' found
[Error] sllistview.dpr(121): Undeclared identifier: 'SubItems'
[Error] sllistview.dpr(139): 'DO' expected but identifier 'Count' found
[Error] sllistview.dpr(160): ',' or ';' expected but '(' found
[Error] sllistview.dpr(160): Declaration expected but identifier 'sFileName' found</span>
A tak wyglada kod, zastanawiam sie jakich modułów musze użyć, ablo co jeszcze zadeklarować
library sllistview;
uses
SysUtils, Classes;
type
ListView: TListView;
{$R *.res}
begin
procedure wczytywanie(AListView: TListView; sFileName: string);stdcall;
var
F: TFileStream;
IdxItem, IdxSubItem, IdxImage: Integer;
W, ItemCount, SubCount: Word;
pText: PChar;
PTemp: PChar;
MySignature: array [0..2] of Char;
sExeName: string;
begin
with AListView do
begin
ItemCount := 0;
SubCount := 0;
sExeName := ExtractFileName(sFileName);
if not FileExists(sFileName) then
begin
// MessageBox(Handle, PChar(Format(Msg1, [sExeName])), 'I/O Error', MB_ICONERROR);
Exit;
end;
F := TFileStream.Create(sFileName, fmOpenRead);
F.Read(MySignature, SizeOf(MySignature));
if MySignature <> 'LVF' then
begin
// MessageBox(Handle, PChar(Format(Msg2, [sExeName])), 'I/O Error', MB_ICONERROR);
Exit;
end;
F.Read(ItemCount, SizeOf(ItemCount));
Items.Clear;
for idxItem := 1 to ItemCount do
begin
with Items.Add do
begin
//Read imageindex
F.Read(SubCount, SizeOf(SubCount));
//Read imageindex
F.Read(IdxImage, SizeOf(IdxImage));
ImageIndex := IdxImage;
//Read the Caption
F.Read(w, SizeOf(w));
pText := StrAlloc(w + 1);
pTemp := StrAlloc(w + 1);
F.Read(pTemp^, W);
StrLCopy(pText, pTemp, W);
Caption := StrPas(pText);
StrDispose(pTemp);
StrDispose(pText);
if SubCount > 0 then
begin
for idxSubItem := 1 to SubCount do
begin
F.Read(w, SizeOf(w));
pText := StrAlloc(w + 1);
pTemp := StrAlloc(w + 1);
F.Read(pTemp^, W);
StrLCopy(pText, pTemp, W);
Items[idxItem - 1].SubItems.Add(StrPas(pText));
StrDispose(pTemp);
StrDispose(pText);
end;
end;
end;
end;
F.Free;
end;
end;
procedure zapisywanie(AListView: TListView; sFileName: string);stdcall;
var
idxItem, idxSub, IdxImage: Integer;
F: TFileStream;
pText: PChar;
sText: string;
W, ItemCount, SubCount: Word;
MySignature: array [0..2] of Char;
begin
//Initialization
with AListView do
begin
ItemCount := 0;
SubCount := 0;
//****
MySignature := 'LVF';
// ListViewFile
F := TFileStream.Create(sFileName, fmCreate or fmOpenWrite);
F.Write(MySignature, SizeOf(MySignature));
if Items.Count = 0 then
// List is empty
ItemCount := 0
else
ItemCount := Items.Count;
F.Write(ItemCount, SizeOf(ItemCount));
if Items.Count > 0 then
begin
for idxItem := 1 to ItemCount do
begin
with Items[idxItem - 1] do
begin
//Save subitems count
if SubItems.Count = 0 then
SubCount := 0
else
SubCount := Subitems.Count;
F.Write(SubCount, SizeOf(SubCount));
//Save ImageIndex
IdxImage := ImageIndex;
F.Write(IdxImage, SizeOf(IdxImage));
//Save Caption
sText := Caption;
w := Length(sText);
pText := StrAlloc(Length(sText) + 1);
StrPLCopy(pText, sText, Length(sText));
F.Write(w, SizeOf(w));
F.Write(pText^, w);
StrDispose(pText);
if SubCount > 0 then
begin
for idxSub := 0 to SubItems.Count - 1 do
begin
//Save Item's subitems
sText := SubItems[idxSub];
w := Length(sText);
pText := StrAlloc(Length(sText) + 1);
StrPLCopy(pText, sText, Length(sText));
F.Write(w, SizeOf(w));
F.Write(pText^, w);
StrDispose(pText);
end;
end;
end;
end;
end;
F.Free;
end;
end;
exports
{ tutaj natomiast eksportujemy same procedury }
zapisywanie(AListView: TListView; sFileName: string) name 'Zapisz',
wczytywanie(AListView: TListView; sFileName: string) name 'Wczytaj';
end.