Solved

Error in ListView Columns

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 99
How to call a form that is in a DLL  from an application? 13 71
Delphi inherited method 6 68
firemonkey Android Listview Sort items 7 10
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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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