Solved

Error in ListView Columns

Posted on 1998-07-26
3
147 Views
Last Modified: 2010-04-04
I Create a Component as follows:

-------
type
  TMyListView = class(TCustomListView)
...

constructor TMyListView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ViewStyle:=vsReport;
  With Columns.Add do Caption:='AAA';
end;
------

But when I try to put this component on a form (in design) I get an error: 'Control '' doesn't have a parent window'
This happens on the line:   With Columns.Add do Caption:='AAA';
Any ideas?
0
Comment
Question by:ronit051397
  • 2
3 Comments
 
LVL 2

Expert Comment

by:freter
ID: 1358719
Right. This error occurs due to the fact that at the moment of executing the line "with columns.add do caption := 'AAA'; ", windows hasn't created the handle for your control yet. I experienced this behaviour myself quite often in my early days ;-)
Here's how to avoid it:
>>>>>>>>>
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, comctrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyListView = class(TCustomListView)
  private
    procedure CreateWnd; override;
  public
    constructor Create(AOwner: TComponent); override;
  end;
var
  Form1: TForm1;

implementation

{$R *.DFM}



constructor TMyListView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ViewStyle:=vsReport;
end;

procedure TMyListView.CreateWnd;
begin
  inherited;
  With Columns.Add do Caption:='AAA';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TMyListView.Create(self) do begin
    parent := self;
    left := 10;
    top := 10;
    visible := true;
  end;
end;

end.

<<<<<<<<<<<<<<<<<<
Don't forget to place a button named Button1 on your form an assign the event Button1CLick to it's click event.

Regards,
Freter

0
 
LVL 5

Author Comment

by:ronit051397
ID: 1358720
Many thanks,
If you post an answer I'll grade it.

Ronit,
0
 
LVL 2

Accepted Solution

by:
freter earned 50 total points
ID: 1358721
Hi Ronit!
I hope it helped you. Here is the answer to grade.

Keep smiling ;-)
Freter
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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