Solved

Error in ListView Columns

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

11 Experts available now in Live!

Get 1:1 Help Now