Solved

Error in ListView Columns

Posted on 1998-07-26
3
144 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

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

16 Experts available now in Live!

Get 1:1 Help Now