Solved

Using ListView macros from CommCtrl?

Posted on 2002-06-11
12
483 Views
Last Modified: 2012-06-21
I'm trying to use ListView macros from the CommCtrl unit to add items on the main application from a DLL file. This works fine, but I realized that when I try to read the items added by my DLL from my main app. I got a "Access violation... Read of address 00000004" :-(

Here is the code I use to add lines from my DLL:

//---------------------------------//

procedure AddLine(Line: string);
var
  i: integer;
  ListItem: LV_ITEM;
begin
  i := ListView_GetItemCount(CtrlOutput);
  ListItem.mask := LVIF_TEXT;
  ListItem.iItem := i;
  ListItem.iSubItem := 0;
  ListItem.pszText := PChar(Line);
  ListItem.cchTextMax := 255;
  i := ListView_InsertItem(CtrlOutput, ListItem);
  ListView_EnsureVisible(CtrlOutput, i, false);
end;

//---------------------------------//

CtrlOutput is the handle to my ListView on the main app.

Can someone please tell me what I'm doing wrong.
0
Comment
Question by:Fraction
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7071760
and how do you read the items from the main app?
0
 
LVL 1

Author Comment

by:Fraction
ID: 7071784
I've tried two ways.

Try 1 (this one use to work):
//---------------------------------//
procedure TForm1.ListView1DblClick(Sender: TObject);
var
  s: string;
begin
  if (Sender as TListView).SelCount>0 then begin
    s := (Sender as TListView).Selected.Caption;
    ...
  end;
end;
//---------------------------------//

Try 2 (I'm improvising):
//---------------------------------//
procedure TForm1.ListView1DblClick(Sender: TObject);
var
  c: array[0..255] of char;
  s: string;
begin
  if (Sender as TListView).SelCount>0 then begin
    ListView_GetItemText(ListView1.Handle, (Sender as TListView).Selected.Index, 0, c, 255);
    ...
  end;
end;
//---------------------------------//
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7071802
First of all, check and see if Selected is nil?

with Sender as TListView do
begin
  if not Assigned(Selected) then
    ShowMessage('Nothing selected!')
  else ShowMessage(Selected.Caption);
end;
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 1

Author Comment

by:Fraction
ID: 7071812
There is nothing selected thogh I dblclick right on the items, that's why I thought the items is not properly added.

Strange by the way, SelCount>0 and Selected is NIL...
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7071830
Hmm... strange... Some questions...

1. is your listview virtual?
2. is the total items in the listview = listview.items.count?
3. if you do a loop to find the selected item, does it work?... as in:
  for i := 0 to ListView1.Count - 1 do
    if ListView1.Items[i].Selected then
      ShowMessage('Item ' + IntToStr(i) + ' is selected...'#13'Caption is ' + ListView1.Items[i].Caption);
0
 
LVL 1

Author Comment

by:Fraction
ID: 7072405
1. No, my ListView is not virtual.
2. Yes, both total items and selected items is equal to Items.Count and SelCount.
3. I tried the loop, but all my items are NIL, so I can't even read Items[i].Selected.
0
 
LVL 1

Author Comment

by:Fraction
ID: 7072841
Guess this question was more difficult than I thoght, so I increase points to 100.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7074650
okay fraction why don't you publish the source for both your app and your dll and i'll see what i can do from there
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9010646
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ with No Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0
 
LVL 1

Author Comment

by:Fraction
ID: 9015955
sorry, i dono how to "PAQ", but you're welcome to delete this question.
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9017761
Sorry, you cant do that... It will be PAQ'd by the moderation team. If you wish to give someone the points, you may do so.

Paul (pnh73)
EE Cleanup Volunteer
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 9102331
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question