Solved

Using ListView macros from CommCtrl?

Posted on 2002-06-11
12
480 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now