Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using ListView macros from CommCtrl?

Posted on 2002-06-11
12
Medium Priority
?
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

610 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