hi i created project to add items to listview with image and exchange items every thing working fine but sadly sometimes while exchange items image object gets nil any idea what iam doing wrong
here is my full project source
to test compile the project then run it and add string first then add item then add string again the click on exchange and see whats happend
need help with listview items with images
Forum kuralları
Forum kurallarını okuyup, uyunuz!
Forum kurallarını okuyup, uyunuz!
need help with listview items with images
- Dosya ekleri
-
- listmvc.rar
- (61.79 KiB) 53 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
in god i trust with every movement i do
graduated student and looking for knowledge
Re: need help with listview items with images
5 downloads no single answer 

بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
in god i trust with every movement i do
graduated student and looking for knowledge
Re: need help with listview items with images
Hi mia.
I have a look at your code.
If you check any object "if exists" by "If Assigned" keyword you must "nil" them after "free" command.
You must make object UnAssigned after free by equaling to NIL.
I have a look at your code.
If you check any object "if exists" by "If Assigned" keyword you must "nil" them after "free" command.
You must make object UnAssigned after free by equaling to NIL.
Kod: Tümünü seç
listms.Free;
listms := Nil;
Re: need help with listview items with images
i freed the memory stream and sit it to nil byt still my image object gets nil after exchange to be more specific
this parameter gets nil after exchange some times look at doUpdateVisual and UpdateVisual parameter comments
this parameter gets nil after exchange some times look at doUpdateVisual and UpdateVisual parameter comments
Kod: Tümünü seç
procedure TURLDownload.DoUpdateVisual;
begin
if Assigned(FOnUpdateVisual) then
FOnUpdateVisual(Self, FUserData// this one is nil, FGif// is nil);
end;
procedure TForm1.UpdateVisual(Sender: TObject; AUserData: Pointer;// this one is nil var AImage: TGifImage // this one is nil );
var
Item: TListItem;
i : integer;
begin
Item := TListItem(AUserData);
if ListView1.Items.IndexOf(Item) = -1 then
Exit;
Item.Data := AImage;
AImage := nil;
if recorder = True then
begin
for i := 0 to ListView1.Items.Count-1
do if ListView1.Items[i].SubItems[3] = IntToStr(UniqueID)
then
begin
ExchangeItems(ListView1, I, 0);
ListView1.Invalidate;
end;
end;
end;
//download code
procedure TURLDownload.Execute;
var
aMs: TMemoryStream;
hSession : HINTERNET;
hService : HINTERNET;
lpBuffer : array[0..1023] of Byte;
dwBytesRead : DWORD;
dwBytesAvail : DWORD;
dwTimeOut : DWORD;
begin
FGif := TGifImage.Create;
try
aMs := TMemoryStream.Create;
hSession := InternetOpen('anyname', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if not Assigned(hSession) then Exit;
try
hService := InternetOpenUrl(hSession, PChar(FUrl), nil, 0, 0, 0);
if hService = nil then
Exit;
try
dwTimeOut := 60000;
InternetSetOption(hService, INTERNET_OPTION_RECEIVE_TIMEOUT, @dwTimeOut, SizeOf(dwTimeOut));
if InternetQueryDataAvailable(hService, dwBytesAvail, 0, 0) then
repeat
if not InternetReadFile(hService, @lpBuffer[0], SizeOf(lpBuffer), dwBytesRead) then
Break;
if dwBytesRead <> 0 then
aMs.WriteBuffer(lpBuffer[0], dwBytesRead);
until dwBytesRead = 0;
finally
InternetCloseHandle(hService);
end;
aMs.Position := 0;
FGif.LoadFromStream(aMs);
FGif.Transparent := True;
finally
aMs.Free;
InternetCloseHandle(hSession);
end;
if Assigned(FOnUpdateVisual) then
begin
Synchronize(DoUpdateVisual);
end;
finally
FGif.Free;
end;
end;
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
in god i trust with every movement i do
graduated student and looking for knowledge
Re: need help with listview items with images
I only looked for where the code stucked. If you press second time the button it was giving access violation error. That problem was the if block which checks freeed "listms" is assigned.
That object sits the nil but stays assigned. The difference is how to look at this.
If you free an object then you must check "is nil" but must not use "is assigned" until equal to nil.
Some of free command do the object unassigned but tmemorystream needs both free and nil.
Make look for (3) of double slash after lines the code below.
The whole code needs to trace more. I will check it out in day time.
That object sits the nil but stays assigned. The difference is how to look at this.
If you free an object then you must check "is nil" but must not use "is assigned" until equal to nil.
Some of free command do the object unassigned but tmemorystream needs both free and nil.
Make look for (3) of double slash after lines the code below.
Kod: Tümünü seç
procedure TForm1.AdditemClick(Sender: TObject);
var
I : integer;
Line: string;
strName, strUniqueID, icon : String;
strSelectedUID : String;
Sl : Tstringlist;
begin
if ListView1.Selected <> nil
then strSelectedUID := Listview1.Selected.SubItems[3]
else strSelectedUID := '';
listview1.Items.BeginUpdate;
try
ListView1.Items.Clear;
finally
listview1.Items.EndUpdate;
end;
if Assigned(listms) then
//SL := TStringList.Create; //removed from here...
begin
SL := TStringList.Create; // Moved to here
try
Sl.LoadFromStream(listms);
for I := 0 to SL.Count -1 do
begin
Line := SL.Strings[I];
parselist(Line, strName, strUniqueID, icon);
boolblink := True;
Add_Item( strName, ListView1, icon, boolblink, strUniqueID, Status);
end;
finally
Sl.Free
end;
listms.Free;
listms := Nil; // append by ARMAN
if strSelectedUID <> '' then
begin
for i := 0 to ListView1.Items.Count-1
do if ListView1.Items[i].SubItems[3] = strSelectedUID
then Listview1.Items[i].Selected := True;
end;
end;
end;
Re: need help with listview items with images
yes the code is really complicated i spend days to discover what happened still don't found it yet . i will wait when you have time
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
in god i trust with every movement i do
graduated student and looking for knowledge