Solved

Using ListView macros from CommCtrl?

Posted on 2002-06-11
12
484 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 110
Making delphi communicate with a c# service 16 111
drawing animated level bar based on numbers 3 103
CheckListBox usage 3 71
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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